-
Notifications
You must be signed in to change notification settings - Fork 41
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
Comments
@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? |
Actually, it have tested it now with the 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:
subprojects {subproject ->
apply plugin: 'java'
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
}
When I comment out the toolchain configuration, it works. When I change 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. |
So the rewrite plugin really works the most effectively when applied a single time in the root project as the The rewrite plugin doesn't take advantage of toolchains to any capacity outside of just looking at what the |
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 |
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:
|
Yeah, my project is private. In case I apply OpenRewrite per project then I see this when I run
I don't see OpenRewrite in However, I found a reference to jackson-module-kotlin in the Gradle repository. So it might actually come from there: |
Hmm. That Gradle one appears to be only a test dependency. Quick question though, does this occur as well when running |
I have seen it fail with tasks:
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 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. |
So I'd suggest only using the latest Gradle plugin as that So I'd make sure that you're on the latest release for all OpenRewrite assets all around, including from your custom recipe library. |
I am still experiencing this issue with the openRewrite gradle plugin version 6.16.4. |
I am using
I am using the Gradle plugin in my multi module project which uses OpenRewrite through a Gradle convention plugin.
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
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:
The text was updated successfully, but these errors were encountered: