Skip to content

Commit

Permalink
[fix] Disable certain errorprone checks for gradle plugins (#504)
Browse files Browse the repository at this point in the history
Fixes #389 

## Before this PR

Gradle plugins would be subjected to certain error prone checks that are only really applicable to code that will run as part of deployed services:

* Slf4jLogsafeArgs
* PreferSafeLoggableExceptions

## After this PR

These checks are disabled for gradle plugin projects, i.e. projects that apply `java-gradle-plugin`.

cc @iamdanfox
  • Loading branch information
dansanduleac authored and bulldozer-bot[bot] committed Jan 15, 2019
1 parent 4e97d86 commit d318e37
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.gradle.api.Project;
import org.gradle.api.file.FileCollection;
import org.gradle.api.plugins.ExtensionAware;
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.tasks.compile.JavaCompile;
import org.gradle.api.tasks.javadoc.Javadoc;
import org.gradle.api.tasks.testing.Test;
Expand All @@ -44,7 +43,6 @@ public final class BaselineErrorProne implements Plugin<Project> {
public void apply(Project project) {
project.getPluginManager().withPlugin("java", plugin -> {
project.getPluginManager().apply(ErrorPronePlugin.class);
JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
String version = Optional.ofNullable(getClass().getPackage().getImplementationVersion())
.orElse("latest.release");
project.getDependencies().add(
Expand All @@ -61,6 +59,15 @@ public void apply(Project project) {
errorProneOptions.check("StreamResourceLeak", CheckSeverity.ERROR);
}));

project.getPluginManager().withPlugin("java-gradle-plugin", appliedPlugin -> {
project.getTasks().withType(JavaCompile.class).configureEach(javaCompile ->
((ExtensionAware) javaCompile.getOptions()).getExtensions()
.configure(ErrorProneOptions.class, errorProneOptions -> {
errorProneOptions.check("Slf4jLogsafeArgs", CheckSeverity.OFF);
errorProneOptions.check("PreferSafeLoggableExceptions", CheckSeverity.OFF);
}));
});

// In case of java 8 we need to add errorprone javac compiler to bootstrap classpath of tasks that perform
// compilation or code analysis. ErrorProneJavacPluginPlugin handles JavaCompile cases via errorproneJavac
// configuration and we do similar thing for Test and Javadoc type tasks
Expand Down

0 comments on commit d318e37

Please sign in to comment.