openrewrite / rewrite-gradle-plugin

OpenRewrite's Gradle plugin.
Apache License 2.0
63 stars 39 forks source link

Plugin classpath is leaking out when unintended #101

Closed shanman190 closed 2 years ago

shanman190 commented 2 years ago

Presently, the plugin needs to compile against several different libraries (rewrite, jackson, etc). These of course are needed for compilation. However, in order to work around the plugin needing Jackson and not wanting to conflict with the shared plugin classpath, internally it uses it's own dependency configuration and isolated classloader. This works great.

However, we are still leaking these dependencies via the plugin's compileClasspath/runtimeClasspath out to the Gradle plugin classpath. This means that if another plugin depends on Jackson, this plugin influences it's version that it receives.

To correct this, we should move from implementation to compileOnly and testImplementation/runtimeOnly so that we no longer leak out the internal classpath that the plugin needs at runtime and will gain via it's internal dependency configuration rewriteDependencies. See: https://github.com/openrewrite/rewrite-gradle-plugin/blob/main/plugin/src/main/java/org/openrewrite/gradle/AbstractRewriteTask.java#L77-L80

shanman190 commented 2 years ago

Using the latest io.moderne.rewrite plugin (as of this writing: 0.11.1) produces the following buildEnvironment:

classpath
\--- io.moderne.rewrite:io.moderne.rewrite.gradle.plugin:0.11.1
     \--- io.moderne:moderne-gradle-plugin:0.11.1
          +--- org.openrewrite:plugin:5.19.0
          |    +--- org.openrewrite:rewrite-core:7.21.0
          |    |    +--- com.fasterxml.jackson.core:jackson-databind:2.13.2.2
          |    |    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.13.2
          |    |    |    |    \--- com.fasterxml.jackson:jackson-bom:2.13.2
          |    |    |    |         +--- com.fasterxml.jackson.core:jackson-annotations:2.13.2 (c)
          |    |    |    |         +--- com.fasterxml.jackson.core:jackson-core:2.13.2 (c)
          |    |    |    |         +--- com.fasterxml.jackson.core:jackson-databind:2.13.2 -> 2.13.2.2 (c)
          |    |    |    |         +--- com.fasterxml.jackson.dataformat:jackson-dataformat-smile:2.13.2 (c)
          |    |    |    |         +--- com.fasterxml.jackson.module:jackson-module-kotlin:2.13.2 (c)
          |    |    |    |         \--- com.fasterxml.jackson.module:jackson-module-parameter-names:2.13.2 (c)
          |    |    |    +--- com.fasterxml.jackson.core:jackson-core:2.13.2
          |    |    |    |    \--- com.fasterxml.jackson:jackson-bom:2.13.2 (*)
          |    |    |    \--- com.fasterxml.jackson:jackson-bom:2.13.2 (*)
          |    |    +--- com.fasterxml.jackson.dataformat:jackson-dataformat-smile:2.13.2
          |    |    |    +--- com.fasterxml.jackson.core:jackson-databind:2.13.2 -> 2.13.2.2 (*)
          |    |    |    +--- com.fasterxml.jackson.core:jackson-core:2.13.2 (*)
          |    |    |    \--- com.fasterxml.jackson:jackson-bom:2.13.2 (*)
          |    |    +--- com.fasterxml.jackson.module:jackson-module-parameter-names:2.13.2
          |    |    |    +--- com.fasterxml.jackson.core:jackson-core:2.13.2 (*)
          |    |    |    +--- com.fasterxml.jackson.core:jackson-databind:2.13.2 -> 2.13.2.2 (*)
          |    |    |    \--- com.fasterxml.jackson:jackson-bom:2.13.2 (*)
          |    |    +--- com.fasterxml.jackson.module:jackson-module-kotlin:2.13.2
          |    |    |    +--- com.fasterxml.jackson.core:jackson-databind:2.13.2 -> 2.13.2.2 (*)
          |    |    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.13.2 (*)
          |    |    |    +--- org.jetbrains.kotlin:kotlin-reflect:1.5.30
          |    |    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.5.30
          |    |    |    |         +--- org.jetbrains:annotations:13.0 -> 23.0.0
          |    |    |    |         \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.5.30
          |    |    |    \--- com.fasterxml.jackson:jackson-bom:2.13.2 (*)
          |    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.21
          |    |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.5.21 -> 1.5.30 (*)
          |    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.21
          |    |    |         \--- org.jetbrains.kotlin:kotlin-stdlib:1.5.21 -> 1.5.30 (*)
          |    |    +--- de.danielbechler:java-object-diff:0.95
          |    |    |    \--- org.slf4j:slf4j-api:1.7.22 -> 1.7.30
          |    |    +--- net.java.dev.jna:jna-platform:5.11.0
          |    |    |    \--- net.java.dev.jna:jna:5.11.0
          |    |    +--- org.graalvm.sdk:graal-sdk:22.0.0.2
          |    |    +--- commons-io:commons-io:2.11.0
          |    |    +--- org.apache.commons:commons-compress:1.21
          |    |    +--- io.micrometer:micrometer-core:1.8.4
          |    |    |    +--- org.hdrhistogram:HdrHistogram:2.1.12
          |    |    |    \--- org.latencyutils:LatencyUtils:2.0.3
          |    |    +--- io.github.classgraph:classgraph:4.8.143
          |    |    \--- org.yaml:snakeyaml:1.30
          |    +--- org.openrewrite:rewrite-hcl:7.21.0
          |    |    +--- org.openrewrite:rewrite-core:7.21.0 (*)
          |    |    +--- org.jetbrains:annotations:23.0.0
          |    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.13.2 (*)
          |    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.21 (*)
          |    |    +--- org.antlr:antlr4:4.9.3
          |    |    |    +--- org.antlr:antlr4-runtime:4.9.3
          |    |    |    +--- org.antlr:antlr-runtime:3.5.2
          |    |    |    +--- org.antlr:ST4:4.3.1
          |    |    |    |    \--- org.antlr:antlr-runtime:3.5.2
          |    |    |    +--- org.abego.treelayout:org.abego.treelayout.core:1.0.3
          |    |    |    +--- org.glassfish:javax.json:1.0.4
          |    |    |    \--- com.ibm.icu:icu4j:69.1
          |    |    \--- io.micrometer:micrometer-core:1.8.4 (*)
          |    +--- org.openrewrite:rewrite-java:7.21.0
          |    |    +--- org.openrewrite:rewrite-core:7.21.0 (*)
          |    |    +--- io.micrometer:micrometer-core:1.8.4 (*)
          |    |    +--- org.jetbrains:annotations:23.0.0
          |    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.13.2 (*)
          |    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.21 (*)
          |    |    +--- org.antlr:antlr4:4.9.3 (*)
          |    |    +--- commons-lang:commons-lang:2.6
          |    |    +--- io.github.classgraph:classgraph:4.8.143
          |    |    +--- org.xerial.snappy:snappy-java:1.1.8.4
          |    |    +--- org.ow2.asm:asm:9.2
          |    |    \--- org.ow2.asm:asm-util:9.2
          |    |         +--- org.ow2.asm:asm:9.2
          |    |         +--- org.ow2.asm:asm-tree:9.2
          |    |         |    \--- org.ow2.asm:asm:9.2
          |    |         \--- org.ow2.asm:asm-analysis:9.2
          |    |              \--- org.ow2.asm:asm-tree:9.2 (*)
          |    +--- org.openrewrite:rewrite-java-11:7.21.0
          |    |    +--- org.openrewrite:rewrite-core:7.21.0 (*)
          |    |    +--- org.openrewrite:rewrite-java:7.21.0 (*)
          |    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.21 (*)
          |    |    +--- io.micrometer:micrometer-core:1.8.4 (*)
          |    |    +--- io.github.classgraph:classgraph:4.8.143
          |    |    \--- org.ow2.asm:asm:9.2
          |    +--- org.openrewrite:rewrite-java-8:7.21.0
          |    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.21 (*)
          |    |    +--- org.openrewrite:rewrite-java:7.21.0 (*)
          |    |    +--- org.ow2.asm:asm:9.2
          |    |    \--- io.micrometer:micrometer-core:1.8.4 (*)
          |    +--- org.openrewrite:rewrite-json:7.21.0
          |    |    +--- org.openrewrite:rewrite-core:7.21.0 (*)
          |    |    +--- org.jetbrains:annotations:23.0.0
          |    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.13.2 (*)
          |    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.21 (*)
          |    |    +--- org.antlr:antlr4:4.9.3 (*)
          |    |    \--- io.micrometer:micrometer-core:1.8.4 (*)
          |    +--- org.openrewrite:rewrite-xml:7.21.0
          |    |    +--- org.openrewrite:rewrite-core:7.21.0 (*)
          |    |    +--- org.jetbrains:annotations:23.0.0
          |    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.13.2 (*)
          |    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.21 (*)
          |    |    +--- org.antlr:antlr4:4.9.3 (*)
          |    |    \--- io.micrometer:micrometer-core:1.8.4 (*)
          |    +--- org.openrewrite:rewrite-yaml:7.21.0
          |    |    +--- org.openrewrite:rewrite-core:7.21.0 (*)
          |    |    +--- org.jetbrains:annotations:23.0.0
          |    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.13.2 (*)
          |    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.21 (*)
          |    |    +--- org.antlr:antlr4:4.9.3 (*)
          |    |    +--- org.yaml:snakeyaml:1.30
          |    |    \--- io.micrometer:micrometer-core:1.8.4 (*)
          |    +--- org.openrewrite:rewrite-properties:7.21.0
          |    |    +--- org.openrewrite:rewrite-core:7.21.0 (*)
          |    |    +--- org.jetbrains:annotations:23.0.0
          |    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.13.2 (*)
          |    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.21 (*)
          |    |    \--- io.micrometer:micrometer-core:1.8.4 (*)
          |    +--- org.openrewrite:rewrite-protobuf:7.21.0
          |    |    +--- org.openrewrite:rewrite-core:7.21.0 (*)
          |    |    +--- org.jetbrains:annotations:23.0.0
          |    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.13.2 (*)
          |    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.21 (*)
          |    |    +--- org.antlr:antlr4:4.9.3 (*)
          |    |    \--- io.micrometer:micrometer-core:1.8.4 (*)
          |    +--- org.openrewrite:rewrite-groovy:7.21.0
          |    |    +--- org.openrewrite:rewrite-java:7.21.0 (*)
          |    |    +--- io.micrometer:micrometer-core:1.8.4 (*)
          |    |    +--- org.jetbrains:annotations:23.0.0
          |    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.13.2 (*)
          |    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.21 (*)
          |    |    \--- org.codehaus.groovy:groovy:3.0.10
          |    +--- org.openrewrite:rewrite-gradle:7.21.0
          |    |    +--- org.openrewrite:rewrite-groovy:7.21.0 (*)
          |    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.21 (*)
          |    |    +--- org.openrewrite:rewrite-properties:7.21.0 (*)
          |    |    +--- com.squareup.okhttp3:okhttp:4.10.0-RC1
          |    |    |    +--- com.squareup.okio:okio:2.9.0
          |    |    |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.4.10 -> 1.5.30 (*)
          |    |    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.4.10 -> 1.5.30
          |    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.4.10 -> 1.5.30 (*)
          |    |    +--- io.github.resilience4j:resilience4j-retry:1.7.0
          |    |    |    +--- io.vavr:vavr:0.10.2
          |    |    |    |    \--- io.vavr:vavr-match:0.10.2
          |    |    |    +--- org.slf4j:slf4j-api:1.7.30
          |    |    |    \--- io.github.resilience4j:resilience4j-core:1.7.0
          |    |    |         +--- io.vavr:vavr:0.10.2 (*)
          |    |    |         \--- org.slf4j:slf4j-api:1.7.30
          |    |    +--- org.codehaus.groovy:groovy-ant:3.0.10
          |    |    |    +--- org.codehaus.groovy:groovy:3.0.10
          |    |    |    +--- org.apache.ant:ant:1.10.12
          |    |    |    |    \--- org.apache.ant:ant-launcher:1.10.12
          |    |    |    +--- org.apache.ant:ant-junit:1.10.12
          |    |    |    |    \--- org.apache.ant:ant:1.10.12 (*)
          |    |    |    +--- org.apache.ant:ant-launcher:1.10.12
          |    |    |    +--- org.apache.ant:ant-antlr:1.10.12
          |    |    |    \--- org.codehaus.groovy:groovy-groovydoc:3.0.10
          |    |    \--- org.codehaus.groovy:groovy-xml:3.0.10
          |    |         \--- org.codehaus.groovy:groovy:3.0.10
          |    +--- com.puppycrawl.tools:checkstyle:9.3
          |    +--- io.micrometer.prometheus:prometheus-rsocket-client:1.3.0
          |    |    +--- io.rsocket:rsocket-core:1.1.0
          |    |    |    +--- io.netty:netty-buffer:4.1.52.Final -> 4.1.53.Final
          |    |    |    |    \--- io.netty:netty-common:4.1.53.Final
          |    |    |    +--- io.projectreactor:reactor-core:3.4.0
          |    |    |    |    \--- org.reactivestreams:reactive-streams:1.0.3
          |    |    |    \--- org.slf4j:slf4j-api:1.7.25 -> 1.7.30
          |    |    +--- io.micrometer:micrometer-registry-prometheus:1.6.1
          |    |    |    +--- io.micrometer:micrometer-core:1.6.1 -> 1.8.4 (*)
          |    |    |    \--- io.prometheus:simpleclient_common:0.9.0
          |    |    |         \--- io.prometheus:simpleclient:0.9.0
          |    |    \--- org.xerial.snappy:snappy-java:1.1.8.2 -> 1.1.8.4
          |    \--- io.rsocket:rsocket-transport-netty:1.1.0
          |         +--- io.rsocket:rsocket-core:1.1.0 (*)
          |         +--- io.projectreactor.netty:reactor-netty-core:1.0.0
          |         |    +--- io.netty:netty-handler:4.1.53.Final
          |         |    |    +--- io.netty:netty-common:4.1.53.Final
          |         |    |    +--- io.netty:netty-resolver:4.1.53.Final
          |         |    |    |    \--- io.netty:netty-common:4.1.53.Final
          |         |    |    +--- io.netty:netty-buffer:4.1.53.Final (*)
          |         |    |    +--- io.netty:netty-transport:4.1.53.Final
          |         |    |    |    +--- io.netty:netty-common:4.1.53.Final
          |         |    |    |    +--- io.netty:netty-buffer:4.1.53.Final (*)
          |         |    |    |    \--- io.netty:netty-resolver:4.1.53.Final (*)
          |         |    |    \--- io.netty:netty-codec:4.1.53.Final
          |         |    |         +--- io.netty:netty-common:4.1.53.Final
          |         |    |         +--- io.netty:netty-buffer:4.1.53.Final (*)
          |         |    |         \--- io.netty:netty-transport:4.1.53.Final (*)
          |         |    +--- io.netty:netty-handler-proxy:4.1.53.Final
          |         |    |    +--- io.netty:netty-common:4.1.53.Final
          |         |    |    +--- io.netty:netty-buffer:4.1.53.Final (*)
          |         |    |    +--- io.netty:netty-transport:4.1.53.Final (*)
          |         |    |    +--- io.netty:netty-codec:4.1.53.Final (*)
          |         |    |    +--- io.netty:netty-codec-socks:4.1.53.Final
          |         |    |    |    +--- io.netty:netty-common:4.1.53.Final
          |         |    |    |    +--- io.netty:netty-buffer:4.1.53.Final (*)
          |         |    |    |    +--- io.netty:netty-transport:4.1.53.Final (*)
          |         |    |    |    \--- io.netty:netty-codec:4.1.53.Final (*)
          |         |    |    \--- io.netty:netty-codec-http:4.1.53.Final
          |         |    |         +--- io.netty:netty-common:4.1.53.Final
          |         |    |         +--- io.netty:netty-buffer:4.1.53.Final (*)
          |         |    |         +--- io.netty:netty-transport:4.1.53.Final (*)
          |         |    |         +--- io.netty:netty-codec:4.1.53.Final (*)
          |         |    |         \--- io.netty:netty-handler:4.1.53.Final (*)
          |         |    +--- io.netty:netty-resolver-dns:4.1.53.Final
          |         |    |    +--- io.netty:netty-common:4.1.53.Final
          |         |    |    +--- io.netty:netty-buffer:4.1.53.Final (*)
          |         |    |    +--- io.netty:netty-resolver:4.1.53.Final (*)
          |         |    |    +--- io.netty:netty-transport:4.1.53.Final (*)
          |         |    |    +--- io.netty:netty-codec:4.1.53.Final (*)
          |         |    |    +--- io.netty:netty-codec-dns:4.1.53.Final
          |         |    |    |    +--- io.netty:netty-common:4.1.53.Final
          |         |    |    |    +--- io.netty:netty-buffer:4.1.53.Final (*)
          |         |    |    |    +--- io.netty:netty-transport:4.1.53.Final (*)
          |         |    |    |    \--- io.netty:netty-codec:4.1.53.Final (*)
          |         |    |    \--- io.netty:netty-handler:4.1.53.Final (*)
          |         |    +--- io.netty:netty-transport-native-epoll:4.1.53.Final
          |         |    |    +--- io.netty:netty-common:4.1.53.Final
          |         |    |    +--- io.netty:netty-buffer:4.1.53.Final (*)
          |         |    |    +--- io.netty:netty-transport:4.1.53.Final (*)
          |         |    |    \--- io.netty:netty-transport-native-unix-common:4.1.53.Final
          |         |    |         +--- io.netty:netty-common:4.1.53.Final
          |         |    |         +--- io.netty:netty-buffer:4.1.53.Final (*)
          |         |    |         \--- io.netty:netty-transport:4.1.53.Final (*)
          |         |    \--- io.projectreactor:reactor-core:3.4.0 (*)
          |         +--- io.projectreactor.netty:reactor-netty-http:1.0.0
          |         |    +--- io.netty:netty-codec-http:4.1.53.Final (*)
          |         |    +--- io.netty:netty-codec-http2:4.1.53.Final
          |         |    |    +--- io.netty:netty-common:4.1.53.Final
          |         |    |    +--- io.netty:netty-buffer:4.1.53.Final (*)
          |         |    |    +--- io.netty:netty-transport:4.1.53.Final (*)
          |         |    |    +--- io.netty:netty-codec:4.1.53.Final (*)
          |         |    |    +--- io.netty:netty-handler:4.1.53.Final (*)
          |         |    |    \--- io.netty:netty-codec-http:4.1.53.Final (*)
          |         |    +--- io.netty:netty-resolver-dns:4.1.53.Final (*)
          |         |    +--- io.netty:netty-transport-native-epoll:4.1.53.Final (*)
          |         |    +--- io.projectreactor.netty:reactor-netty-core:1.0.0 (*)
          |         |    \--- io.projectreactor:reactor-core:3.4.0 (*)
          |         \--- org.slf4j:slf4j-api:1.7.25 -> 1.7.30
          +--- org.openrewrite:rewrite-core:7.21.0 (*)
          +--- org.apache.commons:commons-compress:1.21
          +--- org.tukaani:xz:1.9
          \--- com.eatthepath:fast-uuid:0.2.0

As can be seen from the above buildEnvironment, the plugin classpath explodes via the rewrite-gradle-plugin.

sambsnyd commented 2 years ago

Thanks @shanman190. I think you'll appreciate how much slimmer the new runtimeClasspath is;

runtimeClasspath - Runtime classpath of source set 'main'.
\--- org.openrewrite:rewrite-core:7.22.0-SNAPSHOT