-
I am trying to apply errorprone from a custom plugin of mine. In other words, my plugins sets up errorprone in the host project. I am writing my plugin in Java. What would be the equivalent of this in Java? tasks.named('compileJava') {
options.errorprone {
enabled = true
allErrorsAsWarnings = false
excludedPaths = '.*(/build/generated/).*'
disable('InvalidParam') // False positives on records https://github.com/google/error-prone/issues/2321
}
} I tried this but says no such extension: project.getExtensions().configure("errorprone", (Action<ErrorProneOptions>) errorProneOptions -> {
errorProneOptions.getEnabled().set(true);
errorProneOptions.getAllErrorsAsWarnings().set(false);
errorProneOptions.getExcludedPaths().set(".*(/build/generated/).*");
errorProneOptions.disable("InvalidParam");
}); I tried this but get build error saying invalid compiler option -XepAllErrorsAsWarnings, and so on) 😫 project.getTasks().withType(JavaCompile.class, javaCompile -> {
javaCompile
.getOptions()
.getCompilerArgs()
.addAll(List.of(
"-XepAllErrorsAsWarnings:false",
"-XepExcludedPaths:.*(/build/generated/).*",
"-Xep:InvalidParam:OFF"
));
}); Hope there is a way to apply/configure errorprone in Java. Thanks 🙏 Related but did not work: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The extension is on each project.getTasks().withType(JavaCompile.class).configureEach(javaCompile ->
((ExtensionAware) javaCompile.getOptions()).getExtensions().configure(ErrorProneOptions.class, options -> {
options.getEnabled().set(true); // This should be the default anyway
options.getAllErrorsAsWarnings().set(false);
options.getExcludedPaths().set(".*/build/generated/.*");
options.disable("InvalidParam");
}); |
Beta Was this translation helpful? Give feedback.
The extension is on each
JavaCompile
task'sgetOptions()
, which you have to cast toExtensionAware
(note also how I used withType/configureEach to avoid eager task configuration):