问题 Gradle - compileJava - 删除编译警告


我们使用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流是不是可能,以便我们可以发出警告? 或者还有另一种方式吗?


6481
2018-02-17 22:45


起源

你找到了解决方案吗? - Dinesh
我使用'compileJava.options.warnings = false'和'compileTestJava.options.warnings = false',但这只是解决了一些问题。为了避免浪费太多时间,我去了其他团队并解决了代码方面的“问题”。 - Marcel


答案:


尝试这个:

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

7
2018-02-17 23:13



这为我删除了关于bootstrap的警告,但没有关于弃用的注释。我不确定我是否也想要避开它们,但仍然是+1 - Marcel


尝试添加:

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

2
2018-02-19 01:06



在OSX上使用Java 1.8.0_20这不起作用 - Marcel
无法获得未知的财产'选项' - Xerus
@Xerus我认为cmginty意味着将该行放在JavaCompile任务配置块中,即。 tasks.withType(JavaCompile) { options.compilerArgs += '-Xlint:-deprecation' } - jerryb


到目前为止没有发布任何答案,目前有效(Gradle 4.0.1),所以这里有什么工作:

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

2
2017-07-17 11:17