java Gradle - compileJava - 删除编译警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28572602/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Gradle - compileJava - remove compile Warnings
提问by Marcel
We use Gradle 2.1 and java plugin. During compileJava different warnings occur, for example:
我们使用 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.
We know what they mean but won't fix them (don't ask, other thread :) Is there a way to avoid these messages somehow? They disturb the output a lot:
我们知道它们的意思,但不会修复它们(不要问,其他线程:) 有没有办法以某种方式避免这些消息?它们会严重干扰输出:
: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
Isn't is possible for example to redirect the stderr stream during compileJava so that we can grep out the warnings? Or is there another way?
例如,是否可以在 compileJava 期间重定向 stderr 流,以便我们可以 grep 发出警告?或者还有其他方法吗?
回答by Rene Groeschke
try this:
试试这个:
tasks.withType(JavaCompile) {
options.warnings = false
}
回答by cmcginty
Try adding:
尝试添加:
options.compilerArgs += '-Xlint:-deprecation'
回答by Abhijit Sarkar
No answer posted so far that currently works (Gradle 4.0.1), so here's what does work:
到目前为止还没有发布当前有效的答案(Gradle 4.0.1),所以这里是有效的:
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"