Open andygoossens opened 1 year ago
@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 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 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.
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.
So the rewrite plugin really works the most effectively when applied a single time in the root project as the
rewriteDryRun
andrewriteRun
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).
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
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
Hmm. That Gradle one appears to be only a test dependency.
Quick question though, does this occur as well when running rewriteRun
or rewriteDryRun
?
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 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.
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.
I am still experiencing this issue with the openRewrite gradle plugin version 6.16.4.
Potential workaround: run gradle task with --no-parallel
.
I am using
I am using the Gradle plugin in my multi module project which uses OpenRewrite through a Gradle convention plugin.
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: