Skip to content

fix: add --configure-on-demand to all Gradle commands#2065

Open
mashraf-222 wants to merge 1 commit intomainfrom
fix/gradle-configure-on-demand
Open

fix: add --configure-on-demand to all Gradle commands#2065
mashraf-222 wants to merge 1 commit intomainfrom
fix/gradle-configure-on-demand

Conversation

@mashraf-222
Copy link
Copy Markdown
Contributor

Problem

Gradle multi-module projects with diverse toolchain requirements fail during the configuration phase. Gradle evaluates ALL project configurations even when only one module is targeted (e.g., :rewrite-core:test). If an unrelated module requires an unavailable toolchain (e.g., rewrite-gradle needs JDK 8), the entire build fails.

Discovered during OpenRewrite E2E optimization: rewrite-gradle module's JDK 8 toolchain requirement blocked optimization of rewrite-core.

Root Cause

GradleStrategy constructs Gradle commands without --configure-on-demand. This means all 31+ modules in a project like OpenRewrite get configured, including those not related to the target task.

Fix

Added --configure-on-demand to all 8 Gradle command construction sites in GradleStrategy:

  • install_multi_module_deps()
  • compile_tests() (both module and non-module paths)
  • compile_source_only() (both paths)
  • _get_classpath_uncached()
  • run_tests_via_build_tool()
  • get_test_run_command()

--configure-on-demand tells Gradle to only configure projects needed for the requested task. Available since Gradle 1.4, widely used in large projects. Harmless for single-module projects.

Test Coverage

6 new tests in test_gradle_strategy.py verify --configure-on-demand is present in all command construction paths.

Testing

$ uv run pytest tests/test_languages/test_java/test_gradle_strategy.py -v
6 passed

Gradle evaluates all project configurations during the configuration
phase, even when only one module is targeted. Multi-module projects with
diverse toolchain requirements (e.g., OpenRewrite's rewrite-gradle needs
JDK 8) fail when an unrelated module's toolchain isn't available.

Adds --configure-on-demand to all 8 Gradle command construction sites
so Gradle only configures projects needed for the requested task.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant