Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loader org.openrewrite.gradle.RewriteClassLoader attempted duplicate class definition #212

Open
andygoossens opened this issue Jul 3, 2023 · 10 comments
Labels
bug Something isn't working parser-gradle

Comments

@andygoossens
Copy link

I am using

  • Gradle plugin versions 6.1.7 -> 6.1.9
  • with Gradle v8.1.1

I am using the Gradle plugin in my multi module project which uses OpenRewrite through a Gradle convention plugin.

plugins {
  id 'groovy-gradle-plugin'
}

repositories {
  ...
}

dependencies {
  implementation "org.openrewrite:plugin:6.1.9"
}
plugins {
  id 'org.openrewrite.rewrite'
}

It occurs when I run ./gradlew rewriteDiscover
You may need to rerun this twice as the issue only seems to happen when there were no Gradle changes since the previous build.

Then I will end up with

Execution failed for task ':my-module:rewriteDiscover'.
> loader org.openrewrite.gradle.RewriteClassLoader @6f0d1990 attempted duplicate class definition for com.fasterxml.jackson.module.kotlin.KotlinModule$Builder. (com.fasterxml.jackson.module.kotlin.KotlinModule$Builder is in unnamed module of loader org.openrewrite.gradle.RewriteClassLoader @6f0d1990, parent loader org.gradle.internal.classloader.VisitableURLClassLoader$InstrumentingVisitableURLClassLoader @2b2de543)

While it is broken for Gradle plugin versions v6.1.7 - v6.1.9, it was still working fine with v6.1.6. Which means it is probably related to your recent rewrite-kotlin work.

Stacktrace:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':my-module:rewriteDiscover'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:149)
        at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:282)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:147)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:135)
        at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:51)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:74)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:199)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52)
        at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:42)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:337)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:324)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:317)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:303)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:463)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:380)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:49)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.LinkageError: loader org.openrewrite.gradle.RewriteClassLoader @2aafbb20 attempted duplicate class definition for com.fasterxml.jackson.module.kotlin.KotlinModule$Builder. (com.fasterxml.jackson.module.kotlin.KotlinModule$Builder is in unnamed module of loader org.openrewrite.gradle.RewriteClassLoader @2aafbb20, parent loader org.gradle.internal.classloader.VisitableURLClassLoader$InstrumentingVisitableURLClassLoader @5bd38251)
        at java.base/java.lang.ClassLoader.defineClass1(Native Method)
        at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1012)
        at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
        at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:524)
        at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:427)
        at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:421)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:712)
        at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:420)
        at org.openrewrite.gradle.RewriteClassLoader.loadClass(RewriteClassLoader.java:59)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
        at org.openrewrite.RecipeSerializer.maybeAddKotlinModule(RecipeSerializer.java:101)
        at org.openrewrite.config.YamlResourceLoader.<init>(YamlResourceLoader.java:148)
        at org.openrewrite.config.ClasspathScanningLoader.lambda$scanYaml$0(ClasspathScanningLoader.java:108)
        at io.github.classgraph.ResourceList.forEachInputStreamIgnoringIOException(ResourceList.java:527)
        at org.openrewrite.config.ClasspathScanningLoader.scanYaml(ClasspathScanningLoader.java:107)
        at org.openrewrite.config.ClasspathScanningLoader.<init>(ClasspathScanningLoader.java:75)
        at org.openrewrite.config.Environment$Builder.scanClassLoader(Environment.java:226)
        at org.openrewrite.gradle.isolated.DefaultProjectParser.environment(DefaultProjectParser.java:571)
        at org.openrewrite.gradle.isolated.DefaultProjectParser.listRecipeDescriptors(DefaultProjectParser.java:232)
        at org.openrewrite.gradle.isolated.DefaultProjectParser.discoverRecipes(DefaultProjectParser.java:189)
        at org.openrewrite.gradle.DelegatingProjectParser.lambda$discoverRecipes$1(DelegatingProjectParser.java:89)
        at org.openrewrite.gradle.DelegatingProjectParser.unwrapInvocationException(DelegatingProjectParser.java:147)
        at org.openrewrite.gradle.DelegatingProjectParser.discoverRecipes(DelegatingProjectParser.java:88)
        at org.openrewrite.gradle.RewriteDiscoverTask.run(RewriteDiscoverTask.java:45)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:125)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:58)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:51)
        at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:29)
        at org.gradle.api.internal.tasks.execution.TaskExecution$3.run(TaskExecution.java:242)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:29)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:26)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.run(DefaultBuildOperationRunner.java:47)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:68)
        at org.gradle.api.internal.tasks.execution.TaskExecution.executeAction(TaskExecution.java:227)
        at org.gradle.api.internal.tasks.execution.TaskExecution.executeActions(TaskExecution.java:210)
        at org.gradle.api.internal.tasks.execution.TaskExecution.executeWithPreviousOutputFiles(TaskExecution.java:193)
        at org.gradle.api.internal.tasks.execution.TaskExecution.execute(TaskExecution.java:166)
        at org.gradle.internal.execution.steps.ExecuteStep.executeInternal(ExecuteStep.java:105)
        at org.gradle.internal.execution.steps.ExecuteStep.access$000(ExecuteStep.java:44)
        at org.gradle.internal.execution.steps.ExecuteStep$1.call(ExecuteStep.java:59)
        at org.gradle.internal.execution.steps.ExecuteStep$1.call(ExecuteStep.java:56)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:199)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73)
        at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:56)
        at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:44)
        at org.gradle.internal.execution.steps.RemovePreviousOutputsStep.execute(RemovePreviousOutputsStep.java:67)
        at org.gradle.internal.execution.steps.RemovePreviousOutputsStep.execute(RemovePreviousOutputsStep.java:37)
        at org.gradle.internal.execution.steps.CancelExecutionStep.execute(CancelExecutionStep.java:41)
        at org.gradle.internal.execution.steps.TimeoutStep.executeWithoutTimeout(TimeoutStep.java:74)
        at org.gradle.internal.execution.steps.TimeoutStep.execute(TimeoutStep.java:55)
        at org.gradle.internal.execution.steps.CreateOutputsStep.execute(CreateOutputsStep.java:50)
        at org.gradle.internal.execution.steps.CreateOutputsStep.execute(CreateOutputsStep.java:28)
        at org.gradle.internal.execution.steps.CaptureStateAfterExecutionStep.executeDelegateBroadcastingChanges(CaptureStateAfterExecutionStep.java:100)
        at org.gradle.internal.execution.steps.CaptureStateAfterExecutionStep.execute(CaptureStateAfterExecutionStep.java:72)
        at org.gradle.internal.execution.steps.CaptureStateAfterExecutionStep.execute(CaptureStateAfterExecutionStep.java:50)
        at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:40)
        at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:29)
        at org.gradle.internal.execution.steps.BuildCacheStep.executeWithoutCache(BuildCacheStep.java:166)
        at org.gradle.internal.execution.steps.BuildCacheStep.lambda$execute$1(BuildCacheStep.java:70)
        at org.gradle.internal.Either$Right.fold(Either.java:175)
        at org.gradle.internal.execution.caching.CachingState.fold(CachingState.java:59)
        at org.gradle.internal.execution.steps.BuildCacheStep.execute(BuildCacheStep.java:68)
        at org.gradle.internal.execution.steps.BuildCacheStep.execute(BuildCacheStep.java:46)
        at org.gradle.internal.execution.steps.StoreExecutionStateStep.execute(StoreExecutionStateStep.java:36)
        at org.gradle.internal.execution.steps.StoreExecutionStateStep.execute(StoreExecutionStateStep.java:25)
        at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:36)
        at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:22)
        at org.gradle.internal.execution.steps.SkipUpToDateStep.executeBecause(SkipUpToDateStep.java:91)
        at org.gradle.internal.execution.steps.SkipUpToDateStep.lambda$execute$2(SkipUpToDateStep.java:55)
        at java.base/java.util.Optional.orElseGet(Optional.java:364)
        at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:55)
        at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:37)
        at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:65)
        at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:36)
        at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:37)
        at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:27)
        at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:76)
        at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:37)
        at org.gradle.internal.execution.steps.ValidateStep.execute(ValidateStep.java:94)
        at org.gradle.internal.execution.steps.ValidateStep.execute(ValidateStep.java:49)
        at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:71)
        at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:45)
        at org.gradle.internal.execution.steps.SkipEmptyWorkStep.executeWithNonEmptySources(SkipEmptyWorkStep.java:177)
        at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:81)
        at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:53)
        at org.gradle.internal.execution.steps.RemoveUntrackedExecutionStateStep.execute(RemoveUntrackedExecutionStateStep.java:32)
        at org.gradle.internal.execution.steps.RemoveUntrackedExecutionStateStep.execute(RemoveUntrackedExecutionStateStep.java:21)
        at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsStartedStep.execute(MarkSnapshottingInputsStartedStep.java:38)
        at org.gradle.internal.execution.steps.LoadPreviousExecutionStateStep.execute(LoadPreviousExecutionStateStep.java:36)
        at org.gradle.internal.execution.steps.LoadPreviousExecutionStateStep.execute(LoadPreviousExecutionStateStep.java:23)
        at org.gradle.internal.execution.steps.CleanupStaleOutputsStep.execute(CleanupStaleOutputsStep.java:75)
        at org.gradle.internal.execution.steps.CleanupStaleOutputsStep.execute(CleanupStaleOutputsStep.java:41)
        at org.gradle.internal.execution.steps.AssignWorkspaceStep.lambda$execute$0(AssignWorkspaceStep.java:32)
        at org.gradle.api.internal.tasks.execution.TaskExecution$4.withWorkspace(TaskExecution.java:287)
        at org.gradle.internal.execution.steps.AssignWorkspaceStep.execute(AssignWorkspaceStep.java:30)
        at org.gradle.internal.execution.steps.AssignWorkspaceStep.execute(AssignWorkspaceStep.java:21)
        at org.gradle.internal.execution.steps.IdentityCacheStep.execute(IdentityCacheStep.java:37)
        at org.gradle.internal.execution.steps.IdentityCacheStep.execute(IdentityCacheStep.java:27)
        at org.gradle.internal.execution.steps.IdentifyStep.execute(IdentifyStep.java:47)
        at org.gradle.internal.execution.steps.IdentifyStep.execute(IdentifyStep.java:34)
        at org.gradle.internal.execution.impl.DefaultExecutionEngine$1.execute(DefaultExecutionEngine.java:64)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:146)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:135)
        at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:51)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:74)
        at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:199)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
        at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
        at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73)
        at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52)
        at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:42)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:337)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:324)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:317)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:303)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:463)
        at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:380)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
        at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:49)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:833)
@andygoossens andygoossens added the bug Something isn't working label Jul 3, 2023
@knutwannheden knutwannheden moved this to Backlog in OpenRewrite Jul 3, 2023
@knutwannheden
Copy link
Contributor

@andygoossens Thank you for your detailed report! As we have quite a lot on our plate at this time and it only appears to affect the discovery goal (we haven't had any similar reports for the other goals), I can unfortunately not tell you when we will be able to look into this. Would this be something you would be willing to provide a fix for?

@andygoossens
Copy link
Author

Actually, it have tested it now with the rewriteRun task and it is broken as well.

I have dug a bit further and it seems to be related to the Java toolchain that is configured in my Gradle build...

My setup is as follows:

  • My system uses OpenJDK 17 by default
  • Gradle builds with that system OpenJDK
  • My Gradle build specifies a Java toolchain:
subprojects {subproject ->
  apply plugin: 'java'

  java {
    toolchain {
      languageVersion = JavaLanguageVersion.of(17)
    }
  }
}
  • ./gradlew javaToolchains confirms that there is a single OpenJDK 17 installation.

When I comment out the toolchain configuration, it works. When I change subprojects to allprojects, it works as well.

So I am assuming that OpenRewrite plugin uses the (implicit) toolchain from the root project and that somehow conflicts with the subproject's toolchain. No idea why it would conflict, as I think it is actually the same installation, but here we are. :-)

I am afraid I do not have much time available at the moment as I am quite busy (e.g. migrating things, obviously :-)). Luckily, I have discovered and mentioned a few workarounds here.

@shanman190
Copy link
Collaborator

So the rewrite plugin really works the most effectively when applied a single time in the root project as the rewriteDryRun and rewriteRun desire to run over all available files at once to be the most accurate. If you're applying it multiple times in subprojects, that might be the issue here.

The rewrite plugin doesn't take advantage of toolchains to any capacity outside of just looking at what the JavaCompile task has configured for source and target compatibility (old style) as it's still attempting to target Gradle 4.0 or newer.

@andygoossens
Copy link
Author

So the rewrite plugin really works the most effectively when applied a single time in the root project as the rewriteDryRun and rewriteRun desire to run over all available files at once to be the most accurate. If you're applying it multiple times in subprojects, that might be the issue here.

Right. I was applying it to a selected number of projects in order to reduce the total duration (from +- 2,5 hours to about a minute), and because it was the easiest way to get it working in our Gradle build (e.g. using platform does not work as it probably collides with Spring Boot dependencies plugin; OpenRewrite looks for a testsuite task that does not exist in the root project; and the caffeine dependency is acting up).

@shanman190
Copy link
Collaborator

shanman190 commented Jul 3, 2023

So the missing task issue should be fixed in the latest Gradle plugin.

And I totally understand that aspect of reducing the runtime in large projects. I feel you there.

The other aspect of this is knowing the other plugins surrounding rewrite as what's possibly happening is that one of those other plugins is depending upon Jackson's Kotlin module -- and rewrite does as well -- so when we load that module into our child-first isolated classloader, it throws an error because it's already been loaded into the parent classloader. I'm assuming that the project is private, but I'd suggest taking a look to confirm if the Jackson Kotlin module is in the build environment. You can see the build dependencies by doing the following:

./gradlew buildEnvironment

@andygoossens
Copy link
Author

Yeah, my project is private.

In case I apply OpenRewrite per project then I see this when I run ./gradlew :sub-module:buildEnvironment:

classpath
\--- project :build-conventions
     +--- com.google.protobuf:protobuf-gradle-plugin:0.9.3
     |    \--- com.google.gradle:osdetector-gradle-plugin:1.7.3
     |         \--- kr.motd.maven:os-maven-plugin:1.7.1
     |              \--- com.google.code.findbugs:jsr305:3.0.2
     +--- com.github.bjornvester:xjc-gradle-plugin:1.8.2
     \--- org.openrewrite:plugin:6.1.9
          +--- org.openrewrite:rewrite-bom:8.1.5
          \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0
               +--- org.jetbrains.kotlin:kotlin-stdlib:1.8.0
               |    +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.8.0
               |    \--- org.jetbrains:annotations:13.0
               \--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0
                    \--- org.jetbrains.kotlin:kotlin-stdlib:1.8.0 (*)

I don't see OpenRewrite in ./gradlew buildEnvironment as it is not applied globally. At that level, there is no mention of "kotlin". "jackson" appears a few times but never in combination with "kotlin".

However, I found a reference to jackson-module-kotlin in the Gradle repository. So it might actually come from there:
https://github.com/gradle/gradle/blob/eb27e930e9120bff77261c49818111fcfda2bcdc/build-logic/dependency-modules/src/main/kotlin/gradlebuild/modules/extension/ExternalModulesExtension.kt#L154

@shanman190
Copy link
Collaborator

Hmm. That Gradle one appears to be only a test dependency.

Quick question though, does this occur as well when running rewriteRun or rewriteDryRun?

@andygoossens
Copy link
Author

I have seen it fail with tasks:

  • rewriteDiscover
  • rewriteDryRun
  • rewriteRun

The results are very unpredictable. It seems to work at first, afterwards it starts failing with "attempted duplicate class definition", but I even get "java.lang.ClassNotFoundException: org.openrewrite.ParseError" sometimes. In the beginning I was convinced that v6.1.6 didn't have this issue, but afterwards I have seen it fail as well.

I have noticed that sometimes I was able to fix the problem by deleting the project's .gradle directory. Stopping the daemon was of no use.

Today, I started using plugin v6.1.9 and it seemed to work fine at first. Going to older plugin versions messed things up with the error messages I described earlier. So I tried to stay on v6.1.9. That worked fine until I tried to add my own recipe (= add rewrite dependency, change activeRecipe): the problem came back. Just reverting those changes didn't help. I had to stop the daemon and delete the project's .gradle directory as well.

There seems to be something "sticky" when changing the plugin version and/or plugin configuration. Changing your build configuration just enough (e.g. toolchain changes), might have been a way for Gradle to "reset" things.

@shanman190
Copy link
Collaborator

So I'd suggest only using the latest Gradle plugin as that org.openrewrite.ParseError was moved in rewrite-core:8.1.5 which is included in the rewrite-gradle-plugin:6.1.9. previous versions would likely fail due to class not found exceptions when your recipe is added to the list as it'd be using code from before and after the class was moved.

So I'd make sure that you're on the latest release for all OpenRewrite assets all around, including from your custom recipe library.

@ov7a
Copy link

ov7a commented Jul 26, 2024

I am still experiencing this issue with the openRewrite gradle plugin version 6.16.4.
Potential workaround: run gradle task with --no-parallel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working parser-gradle
Projects
Status: Backlog
Development

No branches or pull requests

5 participants