Skip to content

Pin Tooling-API client default to Gradle 8.14.3#7537

Merged
timtebeek merged 7 commits intomainfrom
tim/gradle-8144
May 1, 2026
Merged

Pin Tooling-API client default to Gradle 8.14.3#7537
timtebeek merged 7 commits intomainfrom
tim/gradle-8144

Conversation

@timtebeek
Copy link
Copy Markdown
Member

@timtebeek timtebeek commented May 1, 2026

Summary

  • Reverts Pick Gradle distribution based on client JVM version #7534, which dispatched the Tooling API client's Gradle distribution by JVM feature version (Gradle 9.1.0 for Java 25+, otherwise 8.14.3).
  • Pins the default to a single hardcoded 8.14.3 (was briefly 8.14.4 on this branch — see below).
  • Drops the now-unused defaultGradleVersion() / javaSpecificationVersion() helpers and the test class that only exercised them.
  • Preserves a wrapperGradleVersion() / isGradle9OrLater() codepath so that callers that supply a gradle-wrapper.properties pointing at Gradle 9 still get the right CLI shape (see Gradle 9 note below). With the 8.14.3 default this code is inert until a wrapper opts in.

Why not 8.14.4 or 9.x?

8.14.4: Kotlin DSL regression

Gradle 8.14.4 introduced a Kotlin DSL compilation regression that breaks plugins {} blocks containing local val declarations. The Kotlin script compiler fails to resolve the PluginDependenciesSpecScope supertype:

Supertypes of the following classes cannot be resolved.
class org.gradle.kotlin.dsl.PluginDependenciesSpecScope, unresolved supertypes: org.gradle.plugin.use.PluginDependenciesSpec

This caused 16 :rewrite-gradle:test failures on this branch (e.g. UpgradePluginVersionTest.upgradeKotlinPluginLocalVariable, UpgradeTransitiveDependencyVersionTest.kotlinDslAddConstraint). The same suite passes against 8.14.3.

9.x: CLI shape changed

Gradle 9 dropped the -b <buildFile> argument used by OpenRewriteModelBuilder to point at non-conventional build files. The replacement is to declare rootProject.buildFileName in settings.gradle, which forces the Tooling API client to synthesize a settings file for tests that don't ship one. Going to 9.x by default would also raise the minimum daemon JVM and force every consumer onto a major upgrade, which is more change than this PR wants to land. The new helpers in OpenRewriteModelBuilder (isGradle9OrLater, settings.gradle writeback) are kept so consumers who do opt into Gradle 9 via their own wrapper still work.

8.14.3: no known regressions

8.14.3 is the same minor the picker chose for Java < 25 before #7534 was reverted, so this PR is a strict simplification of behavior that was already shipping on main. CI runs on Java 21 and Java 25; the rewrite-gradle test JVM is pinned to a Java 21 toolchain so 8.14.3 is JVM-compatible in both matrix legs.

Test plan

  • CI build passes on the PR.
  • Local :rewrite-gradle:test passes against 8.14.3 (the same suite exhibited the 8.14.4 Kotlin DSL failures).

Replaces the per-JVM-version dispatch added in #7534 with a single
hardcoded Gradle distribution. Removes the now-unused helpers and
their test.
@timtebeek
Copy link
Copy Markdown
Member Author

It turns out Gradle 8.x saw a backport of Java 25 support in 8.14.4, which was missed earlier. Proven to work downstream, and simpler than working around the dropped -b flag in 9.x here in a subsequent PR.

timtebeek added 2 commits May 1, 2026 09:23
Gradle 9 dropped -b. When the caller passes a build file at a
non-conventional location, write a temporary settings.gradle with
only rootProject.buildFileName, deleting it in the same finally
block as the init script.
@timtebeek timtebeek marked this pull request as draft May 1, 2026 07:33
timtebeek added 3 commits May 1, 2026 09:37
Determine the Gradle version from the explicit useGradleVersion call
or from gradle-wrapper.properties when useBuildDistribution is in
play. Existing tests on Gradle 8 keep using -b. The settings.gradle
path now writes with CREATE_NEW so it can never overwrite a
user-supplied file, and the cleanup deletes only files we actually
wrote (settingsWritten flag).
Move the Files.write call up into the same block that decides we
need a temporary settings file, and collapse the two nested
try/finally blocks into one outer finally that handles both init
and settings cleanup. settingsWritten still gates the delete so a
race-introduced or pre-existing user file is never touched.
@timtebeek timtebeek changed the title Revert JVM-based Gradle distribution picker, pin to 8.14.4 Pin Tooling-API client default to Gradle 8.14.3 May 1, 2026
8.14.4 has a Kotlin DSL regression that breaks `plugins {}` blocks with
local `val` declarations (16 :rewrite-gradle:test failures); 8.14.3 has
no such regression and matches the pre-#7534 default for Java < 25.
@timtebeek timtebeek marked this pull request as ready for review May 1, 2026 09:46
@timtebeek timtebeek requested a review from shanman190 May 1, 2026 09:47
@timtebeek
Copy link
Copy Markdown
Member Author

Merging already after tests with downstream projects to avoid longer unavailability of builds & snapshots downstream.

@timtebeek timtebeek merged commit 9337667 into main May 1, 2026
1 check passed
@timtebeek timtebeek deleted the tim/gradle-8144 branch May 1, 2026 09:48
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant