Reputation: 3394
I've recently discovered Error Prone and am integrating it into my Android build using the Gradle plugin linked on their page.
Since our project is using Icepick (and some other code generating annotation processors), we have generated source code, which gets compiled in. Unfortunately, some of the generated code triggers warnings in Error Prone, and I'd like to filter that noise out somehow.
The generated code shows up in the app/build/generated/source/apt/debug
directory. How can I exempt this code from Error Prone's steely gaze?
Upvotes: 9
Views: 4417
Reputation: 11608
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
Upvotes: 3
Reputation: 10925
In my case classes were annotated with @AvroGenerated
and -XepDisableWarningsInGeneratedCode
didn't work.
The solution was to exclude build
directory from checks via -XepExcludedPaths:.*/build/.*
Upvotes: 1