Gradle-compileJava-删除编译警告

Gradle-compileJava-删除编译警告,java,gradle,warnings,compiler-warnings,Java,Gradle,Warnings,Compiler Warnings,我们使用Gradle2.1和java插件。编译过程中会出现不同的警告,例如: warning: [options] bootstrap class path not set in conjunction with -source 1.7 Note: ../SomeClass.java uses or overrides a deprecated API. 我们知道它们的意思,但不会修复它们(不要问,其他线程:)有没有办法以某种方式避免这些消息?它们严重干扰了输出: :project1:comp

我们使用Gradle2.1和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
例如,在compileJava过程中是否可以重定向stderr流,以便我们可以显示警告? 或者还有别的办法吗?

试试这个:

tasks.withType(JavaCompile) {
    options.warnings = false
}
尝试添加:

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

到目前为止,还没有发布目前有效的答案(Gradle 4.0.1),所以下面是有效的方法:

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

options.compilerArgs我认为这取决于警告。对于我收到的警告,这起到了作用:

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

恢复了正常状态。

这为我删除了有关引导的警告,但没有删除有关弃用的注释。我不确定我是否也想要避免它们,但是+1 Doesen无法摆脱男性的弃用警告。你找到解决方案了吗?我使用了“compileJava.options.warnings=false”和“compileTestJava.options.warnings=false”,但这只是解决了一些问题。为了避免浪费太多时间,我去了其他团队,解决了他们代码方面的“问题”。呃,我讨厌Gradle让你编辑构建文件的事实。这一定是我选择Maven的最大原因。无法获取未知属性“options”@Xerus我认为cmginty的意思是将该行放入JavaCompile任务配置块,即
tasks.withType(JavaCompile){options.compilerArgs+='-Xlint:-deprecation'}
我讨厌gradle在调用时不允许这样的选项。这就是我喜欢maven的原因。@SridharSarnobat您可以很容易地定义一个特定的属性,并在命令行上设置该属性以完全抑制您想要抑制的内容。