gradle 编译也太严格了吧,使用过期的 api、方法返回值的范型跟方法签名不一样...(自动推断不可以?)


总之解决方案:

    tasks.withType(JavaCompile) {
     // Try to turn them all off automatically
     options.compilerArgs << '-Xlint:none'
     options.compilerArgs << '-nowarn' // same as '-Xlint:none'

     // Turn them off manually
     options.compilerArgs << '-Xlint:-auxiliaryclass'
     options.compilerArgs << '-Xlint:-cast'
     options.compilerArgs << '-Xlint:-classfile'
     options.compilerArgs << '-Xlint:-deprecation'
     options.compilerArgs << '-Xlint:-dep-ann'
     options.compilerArgs << '-Xlint:-divzero'
     options.compilerArgs << '-Xlint:-empty'
     options.compilerArgs << '-Xlint:-fallthrough'
     options.compilerArgs << '-Xlint:-finally'
     options.compilerArgs << '-Xlint:-options'
     options.compilerArgs << '-Xlint:-overloads'
     options.compilerArgs << '-Xlint:-overrides'
     options.compilerArgs << '-Xlint:-path'
     options.compilerArgs << '-Xlint:-processing'
     options.compilerArgs << '-Xlint:-rawtypes'
     options.compilerArgs << '-Xlint:-serial'
     options.compilerArgs << '-Xlint:-static'
     options.compilerArgs << '-Xlint:-try'
     options.compilerArgs << '-Xlint:-unchecked'
     options.compilerArgs << '-Xlint:-varargs'
}

上面两行是关闭全部的警告信息,下面是针对不同的选项进行手动关闭。


完整有效配置:

allprojects{

    apply plugin: 'java'

    repositories {
        mavenLocal()
        maven { url getRepoUrl() }
        mavenCentral()
    }

    tasks.withType(JavaCompile) {
        options.encoding = "UTF-8"
        options.compilerArgs = ['-Xlint:unchecked']

        // Try to turn them all off automatically
        options.compilerArgs << '-Xlint:none'
        options.compilerArgs << '-nowarn' // same as '-Xlint:none'

        // Turn them off manually
        options.compilerArgs << '-Xlint:-auxiliaryclass'
        options.compilerArgs << '-Xlint:-cast'
        options.compilerArgs << '-Xlint:-classfile'
        options.compilerArgs << '-Xlint:-deprecation'
        options.compilerArgs << '-Xlint:-dep-ann'
        options.compilerArgs << '-Xlint:-divzero'
        options.compilerArgs << '-Xlint:-empty'
        options.compilerArgs << '-Xlint:-fallthrough'
        options.compilerArgs << '-Xlint:-finally'
        options.compilerArgs << '-Xlint:-options'
        options.compilerArgs << '-Xlint:-overloads'
        options.compilerArgs << '-Xlint:-overrides'
        options.compilerArgs << '-Xlint:-path'
        options.compilerArgs << '-Xlint:-processing'
        options.compilerArgs << '-Xlint:-rawtypes'
        options.compilerArgs << '-Xlint:-serial'
        options.compilerArgs << '-Xlint:-static'
        options.compilerArgs << '-Xlint:-try'
        options.compilerArgs << '-Xlint:-unchecked'
        options.compilerArgs << '-Xlint:-varargs'
    }


}

同时删掉原配置中存在的 compileJava compileTestJava


参考另一篇文章,解决了***内部API可能会删除的问题

compileJava {
    options.compilerArgs << '-XDignore.symbol.file'
    options.fork = true // may not needed on 1.8
    options.forkOptions.executable = 'javac' // may not needed on 1.8
}


参考:

https://blog.csdn.net/dounine/article/details/64129415

https://stackoverflow.com/questions/34148513/how-do-i-suppress-warnings-when-compiling-an-android-library-with-gradle

https://www.codenong.com/19553336/

PS: 特别无语,有的项目死活都不行,想说一些 *********!

2021-04-22 垃圾、垃圾、垃圾