diff --git a/rewrite-java/build.gradle.kts b/rewrite-java/build.gradle.kts index a805a3589ab..743ad3cae68 100644 --- a/rewrite-java/build.gradle.kts +++ b/rewrite-java/build.gradle.kts @@ -1,5 +1,8 @@ +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar + plugins { id("org.openrewrite.build.language-library") + id("org.openrewrite.build.shadow") } val antlrGeneration by configurations.creating { @@ -18,6 +21,15 @@ tasks.register("generateAntlrSources") { classpath = antlrGeneration } +// Only need checkstyle for the classes that we use to load its configuration files +val checkstyle = configurations.create("checkstyle") +configurations.named("compileOnly").configure { + extendsFrom(checkstyle) +} +configurations.named("testImplementation").configure { + extendsFrom(checkstyle) +} + dependencies { api(project(":rewrite-core")) api(project(":rewrite-yaml")) @@ -28,7 +40,8 @@ dependencies { antlrGeneration("org.antlr:antlr4:4.11.1") implementation("org.antlr:antlr4-runtime:4.11.1") - compileOnly("com.puppycrawl.tools:checkstyle:9.+") { // Pinned to 9.+ because 10.x does not support Java 8: https://checkstyle.sourceforge.io/#JRE_and_JDK + // Pinned to 9.+ because 10.x does not support Java 8: https://checkstyle.sourceforge.io/#JRE_and_JDK + checkstyle("com.puppycrawl.tools:checkstyle:9.+") { isTransitive = false } compileOnly(project(":rewrite-test")) @@ -46,9 +59,6 @@ dependencies { implementation("org.ow2.asm:asm-util:latest.release") testImplementation("org.yaml:snakeyaml:latest.release") - testImplementation("com.puppycrawl.tools:checkstyle:9.+") { // Pinned to 9.+ because 10.x does not support Java 8: https://checkstyle.sourceforge.io/#JRE_and_JDK - isTransitive = false - } testImplementation(project(":rewrite-test")) testImplementation(project(":rewrite-java-test")) testRuntimeOnly(project(":rewrite-java-17")) @@ -76,3 +86,9 @@ tasks.withType { // 1 error exclude("**/JavaParser**", "**/ChangeMethodTargetToStatic**", "**/J.java") } + +tasks.named("shadowJar").configure { + dependsOn(checkstyle) + configurations = listOf(checkstyle) + relocate("com.puppycrawl.tools.checkstyle", "org.openrewrite.tools.checkstyle") +}