Skip to content

gradleParser causes classloading problems when combined with the plugin transformation #323

@blipper

Description

@blipper

How are you running OpenRewrite?

Via custom Gradle tasks and isolated classloaders.

What is the smallest, simplest way to reproduce the problem?

The problem is that rewrite-java/src/main/java/org/openrewrite/java/RemoveUnusedImports.java is a recipe but lives in the same JAR as

We override the getResolvedDependencies but this needs is from another classloader so it blows up
https://github.com/openrewrite/rewrite-gradle-plugin/blob/main/plugin/src/main/java/org/openrewrite/gradle/RewritePlugin.java#L150

Can we move all of these java recipes to their own JAR so they don't conflict with the OpenRewrite java engine itself?

What did you see instead?

> loader constraint violation: when resolving method 'org.openrewrite.groovy.GroovyParser$Builder org.openrewrite.groovy.GroovyParser$Builder.typeCache(org.openrewrite.java.internal.JavaTypeCache)' the class loader org.openrewrite.gradle.RewriteClassLoader @5e6d03b4 of the current class, org/openrewrite/gradle/isolated/DefaultProjectParser, and the class loader org.gradle.internal.classloader.VisitableURLClassLoader$InstrumentingVisitableURLClassLoader @4a2a073c for the method's defining class, org/openrewrite/groovy/GroovyParser$Builder, have different Class objects for the type org/openrewrite/java/internal/JavaTypeCache used in the signature (org.openrewrite.gradle.isolated.DefaultProjectParser is in unnamed module of loader org.openrewrite.gradle.RewriteClassLoader @5e6d03b4, parent loader org.gradle.internal.classloader.VisitableURLClassLoader$InstrumentingVisitableURLClassLoader @4a2a073c; org.openrewrite.groovy.GroovyParser$Builder is in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader$InstrumentingVisitableURLClassLoader @4a2a073c, parent loader org.gradle.internal.classloader.VisitableURLClassLoader$InstrumentingVisitableURLClassLoader @78fef302)

What is the full stack trace of any errors you encountered?

stacktrace output here

Are you interested in contributing a fix to OpenRewrite?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingquestionFurther information is requested

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions