Below a sample configuration tested while building gRPC protos, which is a scenario similar to the OPs with code generated into a target directory: build/generated/*
Generated protos are not marked with @Generated
, so the aforementioned flag -XepDisableWarningsInGeneratedCode
has no effect on the generated code and warnings are still issued.
Also the command line flag has to be prepended by -XDcompilePolicy
as per Gradle output and by -Xplugin:ErrorProne
as per the documentation.
ErrorProne Gradle Plugin via command line args
compileJava {
options.compilerArgs << '-XDcompilePolicy=simple -Xplugin:ErrorProne -XepDisableWarningsInGeneratedCode'
}
The command line approach do not seem to have an effect with modern Gradle, but the next approach does.
ErrorProne Gradle Plugin via options
plugins {
id 'java'
id 'net.ltgt.errorprone' version '3.1.0' // https://github.com/tbroyer/gradle-errorprone-plugin
}
dependencies {
errorprone "com.google.errorprone:error_prone_core:2.20.0" // https://github.com/google/error-prone
}
compileJava {
options.errorprone.disableWarningsInGeneratedCode = true // for @Generated
options.errorprone.excludedPaths = ".*/build/generated/.*" // for other generated scenarios, e.g. Protobuf
}
Environment