What version of OpenRewrite are you using?
I am using
- OpenRewrite v3.34.0 (BOM)
- Gradle plugin v7.36.0
- rewrite-java v
[whatever version the BOM is using]
How are you running OpenRewrite?
I am using the Gradle plugin, and my project is a single module project with an included build.
A repro can be found here: https://github.com/freya022/rewrite-gradle-plugin/tree/repro/retained-rewrite-classpath
What is the smallest, simplest way to reproduce the problem?
- Run
./gradlew :rewriteDryRun, keep the logs
- Modify the prints in
recipes/src/main/kotlin/org/example/TestRecipe.kt, println("Test 1") => println("Test 2")
- Run the same command again, notice the logs are the same, the code was not updated
What did you expect to see?
The recipe should be updated
What did you see instead?
The recipe was not updated and kept running old versions until Gradle was fully restarted
What is the full stack trace of any errors you encountered?
N/A
I'm fairly sure this is an issue of the ClassLoader not being replaced appropriately (adding a dependency in the rewrite configuration updates the recipe), but I'm not sure what the actual fix would be.
From
|
if (rewriteClassLoader == null || |
|
!classpathUrls.equals(rewriteClasspath) || |
|
rewriteClassLoader.getPluginClassLoader() != pluginClassLoader) { |
|
if (rewriteClassLoader != null) { |
|
rewriteClassLoader.close(); |
|
} |
|
rewriteClassLoader = new RewriteClassLoader(classpathUrls, pluginClassLoader); |
|
rewriteClasspath = classpathUrls; |
|
} |
I can see some potential issues, if we assume the plugin class loader doesn't change when only my recipe changes, the classpath URLs will remain the same (only the contents changed) and thus it will reuse the old loader.
What version of OpenRewrite are you using?
I am using
[whatever version the BOM is using]How are you running OpenRewrite?
I am using the Gradle plugin, and my project is a single module project with an included build.
A repro can be found here: https://github.com/freya022/rewrite-gradle-plugin/tree/repro/retained-rewrite-classpath
What is the smallest, simplest way to reproduce the problem?
./gradlew :rewriteDryRun, keep the logsrecipes/src/main/kotlin/org/example/TestRecipe.kt,println("Test 1")=>println("Test 2")What did you expect to see?
The recipe should be updated
What did you see instead?
The recipe was not updated and kept running old versions until Gradle was fully restarted
What is the full stack trace of any errors you encountered?
N/A
Are you interested in contributing a fix to OpenRewrite?
I'm fairly sure this is an issue of the
ClassLoadernot being replaced appropriately (adding a dependency in therewriteconfiguration updates the recipe), but I'm not sure what the actual fix would be.From
rewrite-gradle-plugin/plugin/src/main/java/org/openrewrite/gradle/DelegatingProjectParser.java
Lines 65 to 73 in b3a0c64
I can see some potential issues, if we assume the plugin class loader doesn't change when only my recipe changes, the classpath URLs will remain the same (only the contents changed) and thus it will reuse the old loader.