Migrate spotless, checkstyle, codenarc to convention plugin
MODIFY
buildSrc/build.gradle.kts
buildSrc/build.gradle.kts
plugins {
`java-gradle-plugin`
`kotlin-dsl`
- id("com.diffplug.spotless") version "5.12.4"
+ // When updating, update below in dependencies too
+ id("com.diffplug.spotless") version "5.13.0"
}
spotless {
@@ -39,6 +40,8 @@ dependencies {
implementation("org.eclipse.aether:aether-transport-http:1.1.0")
implementation("org.apache.maven:maven-aether-provider:3.3.9")
+ // When updating, update above in plugins too
+ implementation("com.diffplug.spotless:spotless-plugin-gradle:5.13.0")
implementation("com.google.guava:guava:30.1-jre")
implementation("gradle.plugin.com.github.jengelman.gradle.plugins:shadow:7.0.0")
implementation("org.ow2.asm:asm:7.0-beta")

MODIFY
buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts
buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts
@@ -4,14 +4,14 @@ import org.gradle.api.tasks.testing.logging.TestExceptionFormat
plugins {
`java-library`
groovy
+ checkstyle
+ codenarc
id("org.gradle.test-retry")
id("net.ltgt.errorprone")
-}
-apply(from = "$rootDir/gradle/spotless.gradle")
-apply(from = "$rootDir/gradle/codenarc.gradle")
-apply(from = "$rootDir/gradle/checkstyle.gradle")
+ id("otel.spotless-conventions")
+}
afterEvaluate {
if (findProperty("mavenGroupId") == "io.opentelemetry.javaagent.instrumentation") {
@@ -250,3 +250,15 @@ afterEvaluate {
}
}
}
+
+codenarc {
+ configFile = rootProject.file("gradle/enforcement/codenarc.groovy")
+ toolVersion = "2.0.0"
+}
+
+checkstyle {
+ configFile = rootProject.file("gradle/enforcement/checkstyle.xml")
+ // this version should match the version of google_checks.xml used as basis for above configuration
+ toolVersion = "8.37"
+ maxWarnings = 0
+}

ADD
buildSrc/src/main/kotlin/otel.spotless-conventions.gradle.kts
+plugins {
+ id("com.diffplug.spotless")
+}
+
+spotless {
+ java {
+ googleJavaFormat("1.10.0")
+ licenseHeaderFile(rootProject.file("gradle/enforcement/spotless.license.java"), "(package|import|public|// Includes work from:)")
+ target("src/**/*.java")
+ }
+ groovy {
+ licenseHeaderFile(rootProject.file("gradle/enforcement/spotless.license.java"), "(package|import|class)")
+ }
+ scala {
+ scalafmt()
+ licenseHeaderFile(rootProject.file("gradle/enforcement/spotless.license.java"), "(package|import|public)")
+ target("src/**/*.scala")
+ }
+ kotlin {
+ // ktfmt() // only supports 4 space indentation
+ ktlint().userData(mapOf("indent_size" to "2", "continuation_indent_size" to "2"))
+ licenseHeaderFile(rootProject.file("gradle/enforcement/spotless.license.java"), "(package|import|public)")
+ }
+ format("misc") {
+ // not using "**/..." to help keep spotless fast
+ target(".gitignore", "*.md", "src/**/*.md", "*.sh", "src/**/*.properties")
+ indentWithSpaces()
+ trimTrailingWhitespace()
+ endWithNewline()
+ }
+}

DELETE
gradle/checkstyle.gradle
-apply plugin: "checkstyle"
-
-checkstyle {
- configFile = rootProject.file('gradle/enforcement/checkstyle.xml')
- // this version should match the version of google_checks.xml used as basis for above configuration
- toolVersion = "8.37"
- maxWarnings = 0
-}

DELETE
gradle/codenarc.gradle
-apply plugin: "codenarc"
-
-codenarc {
- configFile rootProject.file('gradle/enforcement/codenarc.groovy')
-
- toolVersion = '2.0.0'
-}

DELETE
gradle/spotless.gradle
-apply plugin: 'com.diffplug.spotless'
-
-spotless {
- java {
- googleJavaFormat('1.10.0')
- licenseHeaderFile rootProject.file('gradle/enforcement/spotless.license.java'), '(package|import|public|// Includes work from:)'
- target 'src/**/*.java'
- }
- groovy {
- licenseHeaderFile rootProject.file('gradle/enforcement/spotless.license.java'), '(package|import|class)'
- }
- scala {
- scalafmt()
- licenseHeaderFile rootProject.file('gradle/enforcement/spotless.license.java'), '(package|import|public)'
- target 'src/**/*.scala'
- }
- kotlin {
- // ktfmt() // only supports 4 space indentation
- ktlint().userData(['indent_size': '2', 'continuation_indent_size': '2'])
- licenseHeaderFile rootProject.file('gradle/enforcement/spotless.license.java'), '(package|import|public)'
- }
- format 'misc', {
- // not using '**/...' to help keep spotless fast
- target '.gitignore', '*.md', 'src/**/*.md', '*.sh', 'src/**/*.properties'
- indentWithSpaces()
- trimTrailingWhitespace()
- endWithNewline()
- }
-}

MODIFY
settings.gradle
settings.gradle
pluginManagement {
plugins {
- id "com.diffplug.spotless" version "5.12.4"
id 'com.github.ben-manes.versions' version '0.27.0'
id "io.github.gradle-nexus.publish-plugin" version "1.0.0"
id "me.champeau.jmh" version "0.6.4"

Migrate spotless, checkstyle, codenarc to convention plugin (#3310)