openrewrite / rewrite-gradle-plugin

OpenRewrite's Gradle plugin.
Apache License 2.0
60 stars 37 forks source link

Gradle (8.4, JDK 21) rewrite tasks hang indefinitely #234

Closed mmoayyed closed 9 months ago

mmoayyed commented 11 months ago

What version of OpenRewrite are you using?

I am using:

Gradle Plugin: 6.3.18 Gradle: 8.4 JDK: 21 MacOS Ventura 13.5.2

How are you running OpenRewrite?

./gradlew rewriteDryRun -DactiveRecipe=CASUpgrade6612 --no-configuration-cache --debug --no-parallel

Configuration:

rewrite {
    def activeRecipe = providers.systemProperty("activeRecipe").getOrNull()
    if (activeRecipe != null) {
        def file = project.getRootProject().file("openrewrite/${activeRecipe}.yml")
        def out = services.get(StyledTextOutputFactory).create("cas")
        out.withStyle(Style.Success).println("Activating recipe ${file}")
        configFile = file
    }
}

Recipe:

---
type: specs.openrewrite.org/v1beta/recipe
name: CASUpgrade6612
displayName: Upgrade the CAS to version 6.6.12
recipeList:
  - org.openrewrite.gradle.AddProperty:
      key: cas.version
      value: 6.6.12
      overwrite: true
      filePattern: 'gradle.properties'

What is the smallest, simplest way to reproduce the problem?

git clone --depth 1 git@github.com:apereo/cas-overlay-template.git
# With JDK 21
./gradlew rewriteDryRun -DactiveRecipe=CASUpgrade6612 --no-configuration-cache --debug --no-parallel

What did you expect to see?

The gradle.properties file changes its version to 6.6.12

What is the full stack trace of any errors you encountered?

Build hangs with (Gradle debug logs):

2023-10-06T18:46:49.514+0400 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
2023-10-06T18:46:49.514+0400 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
2023-10-06T18:46:49.514+0400 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
2023-10-06T18:46:49.514+0400 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
2023-10-06T18:46:49.514+0400 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
2023-10-06T18:46:49.514+0400 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
2023-10-06T18:46:59.518+0400 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
2023-10-06T18:46:59.518+0400 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
2023-10-06T18:46:59.519+0400 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
2023-10-06T18:46:59.519+0400 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
2023-10-06T18:46:59.519+0400 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
2023-10-06T18:46:59.519+0400 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.

Tried this with all different versions of Gradle 8.4, from RC1 to proper GA.

Are you interested in contributing a fix to OpenRewrite?

With a bit of guidance, certainly.

timtebeek commented 11 months ago

Hi @mmoayyed , good seeing you here! As far as I'm aware you're certainly one of the earlier ones trying out OpenRewrite on Java 21. Not quite sure that's supported yet; we're tracking support with some small blockers in

Would running on Java 17 for now be an option? And does that give any different results?

Note that you're also able to compose and run recipes quickly through the Moderne platform; Using the recipe builder at https://app.moderne.io/recipes/builder you can for instance run against https://app.moderne.io/organizations/apereo/java-cas-client?branch=master&origin=github.com

That way you should be able to quickly explore what changes a collection of recipes would make: https://app.moderne.io/results/pXfDfkhLs/details/eyJfX3R5cGVuYW1lIjoiR2l0SHViUmVwb3NpdG9yeSIsIm9yaWdpbiI6ImdpdGh1Yi5jb20iLCJwYXRoIjoiYXBlcmVvL2phdmEtY2FzLWNsaWVudCIsImJyYW5jaCI6Im1hc3RlciJ9?referrer=%2Fresults%2FpXfDfkhLs image

Hope that helps you iterate quicker, such that you're able to get up and running before distributing your own recipes.

mmoayyed commented 11 months ago

Thank you very much for the details and the screenshot. Much appreciated.

ATM, running on JDK 17 is no longer an option as the codebase/project I am primarily working on does require JDK 21. I will nonetheless give this a try once more with the Moderne platform and see if I may get better results.

Is there anything I can do to help out regarding JDK 21 support? Something to test, etc?

timtebeek commented 11 months ago

Glad to hear I could help in some way; we expect any recipes that you compose or develop to work on Java 21 just as well, once we have parser support there, so you should already be able to develop recipes and try those on any Java 8 - 17 projects.

There's nothing related to Java 21 to test yet, but you can follow along to https://github.com/openrewrite/rewrite-migrate-java/issues/305 to get updates as we work. Thanks for the offer to help! Really good to have feedback as we work. :)

timtebeek commented 11 months ago

Quick note to let you know we've added a Java 21 specific parser to https://github.com/openrewrite/rewrite/tree/main/rewrite-java-21 ; Haven't tried it out on projects through the plugins yet, but there's progress towards support.

mmoayyed commented 11 months ago

Very nice. Thank you for the update.

timtebeek commented 9 months ago

Checking back in with some fresh perspective (for myself). It turns out Gradle 8.4 does not yet running on Java 21 itself; it does support building projects that themselves use Java 21 through toolchains; but Gradle itself needs to be launched with Java < 20.

Are you already using toolchains in your project?

java {
    toolchain {
        languageVersion.set(JavaLanguageVersion.of(21))
    }
}

Once Gradle 8.5 becomes available you should be able to use the Java 21 to run Gradle itself as well. I believe there's a 8.5 RC out that you can try to see if that resolves your issues. Do let us know if that means this issue can be closed!

mmoayyed commented 9 months ago

Thank you. ATM I am running with Gradle 8.5 RC4 and OpenRewrite 6.5.9 and the issue is gone.

timtebeek commented 9 months ago

Ah perfect, thanks for confirming! Good to know there's no issues coming up to 8.5 :)