Gradle - compileJava - 删除编译警告

时间:2015-02-17 22:45:27

标签: java gradle warnings compiler-warnings

我们使用Gradle 2.1和java插件。在compileJava期间会发生不同的警告,例如:

warning: [options] bootstrap class path not set in conjunction with -source 1.7
Note: ../SomeClass.java uses or overrides a deprecated API.

我们知道他们的意思,但不会修复它们(不要问,其他线程:)是否有办法以某种方式避免这些消息?它们会大大扰乱输出:

:project1:compileJava
warning: [options] bootstrap class path not set in conjunction with -source 1.7
Note: SomeClass.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 warning
:project1:processResources
:project1:classes
:project1:jar
:project2:compileJava
warning: [options] bootstrap class path not set in conjunction with -source 1.7
1 warning
:project2:processResources
:project2:classes
:project2:jar
:project2:war

例如,在compileJava期间是否可以重定向stderr流,以便我们可以发出警告? 或者还有另一种方式吗?

4 个答案:

答案 0 :(得分:7)

试试这个:

tasks.withType(JavaCompile) {
    options.warnings = false
}

答案 1 :(得分:2)

尝试添加:

options.compilerArgs += '-Xlint:-deprecation'

答案 2 :(得分:2)

到目前为止尚未发布当前有效的答案(Gradle 4.0.1),所以这里有什么工作:

options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"

答案 3 :(得分:0)

我认为这确实取决于警告。对于我收到的警告,此方法有效:

    tasks.withType(JavaCompile) {
        options.compilerArgs += ["-nowarn", "-XDenableSunApiLintControl"]
    }

恢复健康。

相关问题