Gradle - compileJava - remove compile Warnings

2022-09-02 04:41:30

我们使用Gradle 2.1和java插件。在编译Java期间,会出现不同的警告,例如:

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

例如,在编译Java期间重定向stderr流,以便我们可以删除警告吗?还是有其他方法?


答案 1

试试这个:

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

答案 2

尝试添加:

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

推荐