如何在Java gradle项目中禁用生成代码中的警告

如何在Java gradle项目中禁用生成代码中的警告,java,gradle,generated-code,immutables-library,Java,Gradle,Generated Code,Immutables Library,我希望有一个gradle项目,它不会对我编写的任何代码生成编译器警告。我还想使用生成我的一些类。目前,我还没有找到一种方法来禁用生成代码的警告 目前我有一个gradle.properties文件,其中包括: org.gradle.warning.mode = all immutables_version = 2.7.4 在我的模块的build.gradle中,我有以下相关部分: apply plugin: "java" dependencies { annotationProcess

我希望有一个gradle项目,它不会对我编写的任何代码生成编译器警告。我还想使用生成我的一些类。目前,我还没有找到一种方法来禁用生成代码的警告

目前我有一个
gradle.properties
文件,其中包括:

org.gradle.warning.mode = all
immutables_version = 2.7.4
在我的模块的
build.gradle
中,我有以下相关部分:

apply plugin: "java"

dependencies {
    annotationProcessor("org.immutables:value:${immutables_version}")
    compileOnly("org.immutables:value-annotations:${immutables_version}")
}

project.sourceSets.configureEach { sourceSet ->
    def generatedSourcesDir = project.file("${project.buildDir}/generated/${sourceSet.name}/java")
    generatedSourcesDir.mkdirs()
    sourceSet.java { source ->
        if (!source.srcDirs.contains(generatedSourcesDir)) {
            source.srcDir generatedSourcesDir
        }
    }

    project.tasks.named(sourceSet.getCompileTaskName("java").configure {
        options.annotationProcessorGeneratedSourcesDirectory = generatedSourcesDir
        options.compilerArgs << "-Werror"
    }
}
apply插件:“java”
依赖关系{
annotationProcessor(“org.immutables:value:${immutables\u version}”)
compileOnly(“org.immutables:值注释:${immutables\u version}”)
}
project.sourceSet.configureEach{sourceSet->
def generatedSourcesDir=project.file(“${project.buildDir}/generated/${sourceSet.name}/java”)
generatedSourcesDir.mkdirs()
sourceSet.java{source->
如果(!source.srcDirs.contains(generatedSourcesDir)){
source.srcDir生成的sourcesdir
}
}
project.tasks.named(sourceSet.getCompileTaskName(“java”).configure{
options.annotationProcessorGeneratedSourcesDirectory=generatedSourcesDir
options.compilerArgs任务::compileJava失败
警告:使用相同内容重新生成的文件:
错误:发现警告并指定了-Werror
1错误
1警告
...

是否有任何编译器设置可用于排除生成代码的警告?我知道允许您排除带有
选项的文件。errorporent.disablewarningsingeratedcode=true
,但我在普通的gradle编译选项中看不到类似的设置。

我不确定我是否理解正确。是否要编译项目d它不工作?为什么要设置编译参数
-Werror
?删除它,编译将再次工作。或者您可以在源代码中修复警告。@AndiCover抱歉没有像我应该的那样清楚:我想在我编写的所有源代码上使用编译器参数
-Werror
,但不是关于生成的代码。很遗憾,我无法修复源代码中的错误,因为该代码已自动为我生成。我不确定我是否理解正确。您想编译项目,但它不起作用?为什么要设置编译参数
-Werror
?删除它,编译将再次起作用。或者您可以请修复源代码中的警告。@很抱歉没有像我应该的那样清楚:我想对我编写的所有源代码使用编译器参数
-Werror
,但对生成的代码不使用。很遗憾,我无法修复源代码中的错误,因为该代码是自动为我生成的。
Running './gradlew :<module>:compileJava'...

> Task :<module>:compileJava FAILED
warning: Regenerated file with the same content: <generated immutables file>
error: warnings found and -Werror specified
1 error
1 warning
...