simonsays
simonsays

Reputation: 438

How to disable warnings in generated code in Java gradle project

I would like to have a gradle project that generates no compiler warnings on any code that I write. I would also like to use the Immutables library to generate some of my classes. At the moment I have no found a way to disable warnings for generated code.

Currently I have a gradle.properties file that includes:

org.gradle.warning.mode = all
immutables_version = 2.7.4

In my module's build.gradle I have the following relevant portions:

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"
    }
}

When I try to compile I get output that looks like:

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
...

Is there any compiler setting I can use to exclude warnings for my generated code? I know the Error Prone compiler lets you exclude files with options.errorprone.disableWarningsInGeneratedCode = true but I don't see anything like that in the normal gradle compile options.

Upvotes: 4

Views: 1429

Answers (0)

Related Questions