Extract errorprone configuration to separate plugin
MODIFY
build.gradle
build.gradle
@@ -61,81 +61,6 @@ allprojects {
}
}
- plugins.withId('net.ltgt.errorprone') {
- dependencies {
- errorprone "com.google.errorprone:error_prone_core"
- }
-
- tasks.withType(JavaCompile).configureEach {
- options.errorprone {
- enabled = rootProject.findProperty("disableErrorProne") != "true"
- disableWarningsInGeneratedCode = true
- allDisabledChecksAsWarnings = true
-
- excludedPaths = ".*/build/generated/.*"
-
- // Doesn't work well with Java 8
- disable("FutureReturnValueIgnored")
-
- // Require Guava
- disable("AutoValueImmutableFields")
- disable("StringSplitter")
- disable("ImmutableMemberCollection")
-
- // Don't currently use this (to indicate a local variable that's mutated) but could
- // consider for future.
- disable("Var")
-
- // Don't support Android without desugar
- disable("AndroidJdkLibsChecker")
- disable("Java7ApiChecker")
- disable("StaticOrDefaultInterfaceMethod")
-
- // Great check, but for bytecode manipulation it's too common to separate over
- // onEnter / onExit
- // TODO(anuraaga): Only disable for auto instrumentation project.
- disable("MustBeClosedChecker")
-
- // Common to avoid an allocation. Revisit if it's worth opt-in suppressing instead of
- // disabling entirely.
- disable("MixedMutabilityReturnType")
-
- // We end up using obsolete types if a library we're instrumenting uses them.
- disable("JdkObsolete")
- disable("JavaUtilDate")
-
- // Limits API possibilities
- disable("NoFunctionalReturnType")
-
- // Storing into a variable in onEnter triggers this unfortunately.
- // TODO(anuraaga): Only disable for auto instrumentation project.
- disable("UnusedVariable")
-
- // TODO(anuraaga): Remove this, we use this pattern in several tests and it will mean
- // some moving.
- disable("DefaultPackage")
-
- // TODO(anuraaga): Remove this, all our advice classes miss constructors but probably should
- // address this.
- disable("PrivateConstructorForUtilityClass")
-
- // TODO(anuraaga): Remove this, probably after instrumenter API migration instead of dealing
- // with older APIs.
- disable("InconsistentOverloads")
- disable("TypeParameterNaming")
-
- // We don't use tools that recognize.
- disable("InlineMeSuggester")
- disable("DoNotCallSuggester")
-
- if (name.contains("Jmh") || name.contains("Test")) {
- disable("HashCodeToString")
- disable("MemberName")
- }
- }
- }
- }
-
plugins.withId('net.ltgt.nullaway') {
dependencies {
errorprone "com.uber.nullaway:nullaway"

ADD
buildSrc/src/main/kotlin/otel.errorprone-conventions.gradle.kts
+import net.ltgt.gradle.errorprone.errorprone
+
+plugins {
+ id("net.ltgt.errorprone")
+}
+
+dependencies {
+ errorprone("com.google.errorprone:error_prone_core")
+}
+
+val disableErrorProne = gradle.startParameter.projectProperties.get("disableErrorProne")
+
+tasks {
+ withType<JavaCompile>().configureEach {
+ options.errorprone {
+ enabled = disableErrorProne != "true"
+
+ disableWarningsInGeneratedCode.set(true)
+ allDisabledChecksAsWarnings.set(true)
+
+ excludedPaths.set(".*/build/generated/.*")
+
+ // Doesn't work well with Java 8
+ disable("FutureReturnValueIgnored")
+
+ // Require Guava
+ disable("AutoValueImmutableFields")
+ disable("StringSplitter")
+ disable("ImmutableMemberCollection")
+
+ // Don't currently use this (to indicate a local variable that's mutated) but could
+ // consider for future.
+ disable("Var")
+
+ // Don't support Android without desugar
+ disable("AndroidJdkLibsChecker")
+ disable("Java7ApiChecker")
+ disable("StaticOrDefaultInterfaceMethod")
+
+ // Great check, but for bytecode manipulation it's too common to separate over
+ // onEnter / onExit
+ // TODO(anuraaga): Only disable for auto instrumentation project.
+ disable("MustBeClosedChecker")
+
+ // Common to avoid an allocation. Revisit if it's worth opt-in suppressing instead of
+ // disabling entirely.
+ disable("MixedMutabilityReturnType")
+
+ // We end up using obsolete types if a library we're instrumenting uses them.
+ disable("JdkObsolete")
+ disable("JavaUtilDate")
+
+ // Limits API possibilities
+ disable("NoFunctionalReturnType")
+
+ // Storing into a variable in onEnter triggers this unfortunately.
+ // TODO(anuraaga): Only disable for auto instrumentation project.
+ disable("UnusedVariable")
+
+ // TODO(anuraaga): Remove this, we use this pattern in several tests and it will mean
+ // some moving.
+ disable("DefaultPackage")
+
+ // TODO(anuraaga): Remove this, all our advice classes miss constructors but probably should
+ // address this.
+ disable("PrivateConstructorForUtilityClass")
+
+ // TODO(anuraaga): Remove this, probably after instrumenter API migration instead of dealing
+ // with older APIs.
+ disable("InconsistentOverloads")
+ disable("TypeParameterNaming")
+
+ // We don't use tools that recognize.
+ disable("InlineMeSuggester")
+ disable("DoNotCallSuggester")
+
+ if (name.contains("Jmh") || name.contains("Test")) {
+ disable("HashCodeToString")
+ disable("MemberName")
+ }
+ }
+ }
+}

MODIFY
buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts
buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts
@@ -9,8 +9,8 @@ plugins {
codenarc
id("org.gradle.test-retry")
- id("net.ltgt.errorprone")
+ id("otel.errorprone-conventions")
id("otel.spotless-conventions")
}

Extract errorprone configuration to separate plugin (#3387)