Skip to content

Skip evaluated projects when aligning Java versions - #60374

Draft
ide wants to merge 1 commit into
react:mainfrom
expo:@ide/gradle-jdk-sweep-evaluated-projects
Draft

ide wants to merge 1 commit into
react:mainfrom
expo:@ide/gradle-jdk-sweep-evaluated-projects

Conversation

@ide

@ide ide commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Summary:

JdkConfiguratorUtils.configureJavaToolChains runs for each application that applies the React plugin, and registers a finalizeDsl callback on every Android project in the build to set Java 17. AGP finalizes a project's DSL when the project is evaluated, and AGP 9 fails the build when finalizeDsl is called after that:

It is too late to call `finalizeDsl` as the DSL finalization blocks have already been executed.

So the build fails during configuration in two cases:

  • Gradle evaluates a library before the app. ReactRootProjectPlugin makes every other project depend on the evaluation of :app, so this needs a build that does not apply that plugin, or one in which the app that applies the React plugin is not the :app project.
  • Two applications apply the plugin. The second one's call reaches the first, which is already evaluated.

ReactPlugin already skips evaluated projects for the same reason when it applies the namespace fallback to libraries (#57290). This change does the same in configureJavaToolChains. A library that is evaluated before the app keeps the Java version it declares.

Changelog:

[ANDROID] [FIXED] - Fix "It is too late to call finalizeDsl" when a library is evaluated before the app or a build has two apps

Test Plan:

JdkConfiguratorUtilsTest (new) builds projects with ProjectBuilder, applies the Android plugins, and evaluates them:

  • configureJavaToolChains_withALibraryEvaluatedBeforeTheApp_alignsTheApp
  • configureJavaToolChains_withTwoApps_alignsBoth
./gradlew -p packages/gradle-plugin :react-native-gradle-plugin:test --tests com.facebook.react.utils.JdkConfiguratorUtilsTest --max-workers=4 --console=plain
  • upstream/main 94aee19ac9 with only the new test file: both tests fail with the finalizeDsl error above, thrown from JdkConfiguratorUtils.configureJavaToolChains.
  • With the fix: both pass.
  • With the fix changed to skip every project: both fail on the assertion ([11, 11] instead of 17), so the tests do check that the versions are set.

Also run: ktfmt --dry-run --set-exit-if-changed on the two changed Kotlin files (clean), git diff --check (clean).

Not run: the rest of the plugin's tests, and a real Android build in either failing layout.

🤖 Generated with Claude Code

`configureJavaToolChains` runs for each application that applies the
React plugin and registers a `finalizeDsl` callback on every Android
project in the build. AGP finalizes a project's DSL when the project is
evaluated, and AGP 9 fails the build when `finalizeDsl` is called after
that:

    It is too late to call `finalizeDsl` as the DSL finalization
    blocks have already been executed.

So the build fails during configuration when Gradle evaluates a library
before the app, and when a second app applies the plugin after the
first has been evaluated. `ReactRootProjectPlugin` orders `:app` before
every other project, so the first case needs a build that does not
apply that plugin, or whose React app is not `:app`.

Skip projects that are already evaluated, as the namespace fallback in
`ReactPlugin` already does. A library evaluated before the app keeps
the Java version it declares.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Nov 28, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 28, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant