Skip to content

Java recipes are not getting updated #453

Description

@freya022

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?

  1. Run ./gradlew :rewriteDryRun, keep the logs
  2. Modify the prints in recipes/src/main/kotlin/org/example/TestRecipe.kt, println("Test 1") => println("Test 2")
  3. 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

Are you interested in contributing a fix to OpenRewrite?

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions