Skip to content

9.0 (fix): capture indy Provider in VerifyNativeImageIndy instead of casting Task - #17319

Merged
codeconsole merged 3 commits into
apache:9.0.xfrom
codeconsole:fix-verify-native-indy-cast
Dec 4, 2026
Merged

codeconsole merged 3 commits into
apache:9.0.xfrom
codeconsole:fix-verify-native-indy-cast

Conversation

@codeconsole

Copy link
Copy Markdown
Contributor

Summary

  • Updated GrailsGradlePlugin.VerifyNativeImageIndy to accept a Provider<Boolean> indyDisabled captured at task configuration time (project.provider { compile.groovyOptions.optimizationOptions.get('indy') == Boolean.FALSE }) instead of casting the Task argument to GroovyCompile inside execute(Task).
  • Added a functional test in GrailsNativeImageDefaultsSpec verifying that the verifyNativeImageIndy doFirst action executes cleanly against a plain DefaultTask both when invokedynamic is enabled (passes) and when disabled late via afterEvaluate (fails with the expected message).

Motivation

Plugins that wrap or replace compileGroovy with a custom DefaultTask (such as jdaugherty/incremental-groovy-compile) and forward compileGroovy's doFirst actions fail with ClassCastException: ... cannot be cast to org.gradle.api.tasks.compile.GroovyCompile when VerifyNativeImageIndy.execute(Task) casts its task argument. Capturing a Provider<Boolean> preserves lazy evaluation for late afterEvaluate overrides while avoiding the GroovyCompile cast and remaining configuration-cache safe.

I targeted 9.0.x because VerifyNativeImageIndy was introduced on 9.0.x.

Verification

  • Ran ./gradlew :grails-gradle-plugins:codenarcMain :grails-gradle-plugins:test --tests "*GrailsNativeImageDefaultsSpec" in grails-gradle/ (all 13 tests passed, CodeNarc clean).

@codeconsole codeconsole changed the title Capture indy Provider in VerifyNativeImageIndy instead of casting Task 9.0 (fix): capture indy Provider in VerifyNativeImageIndy instead of casting Task Dec 4, 2026
@codeconsole
codeconsole requested review from jamesfredley, jdaugherty, matrei and sbglasius and removed request for jdaugherty December 4, 2026 04:43
@jdaugherty

Copy link
Copy Markdown
Contributor

We should put this change in 8.0.x as it's really a bug fix.

@codeconsole

codeconsole commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor Author

VerifyNativeImageIndy (and its doFirst("verifyNativeImageIndy", ...) action) only exists on 9.0.x — on 8.0.x and 8.1.x, configureNativeImage only sets grailsExt.indy.convention(true) without registering any compile task action. That is why I targeted this PR at 9.0.x (while targeting #17318 and #17320 at 8.0.x).

sbglasius
sbglasius previously approved these changes Dec 4, 2026

@sbglasius sbglasius left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix looks right: the indy check no longer casts the task, and the Provider still reads the option when the action runs, so a late afterEvaluate override is still caught.

Two small things:

  • The Javadoc on VerifyNativeImageIndy still says it holds nothing so the configuration cache can store it. It now holds a Provider, so that sentence should change.
  • When the action is forwarded, the message names the wrapper task (:runForwardedVerifyAction ... remove the indy = false compiler option set on it), but the option is on compileGroovy. Capturing compile.path when the action is configured would point users at the right task.

Optional: the PR says this stays configuration-cache safe. Running the existing late-indy compileGroovy case once with --configuration-cache would show that.

On the 8.0.x question: VerifyNativeImageIndy only exists on 9.0.x, so 9.0.x is the right base here.

@jamesfredley jamesfredley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requested changes. The configuration cache can freeze the indy check before compilation, and a forwarded verifier reads the source task.

project.tasks.withType(GroovyCompile).configureEach { GroovyCompile compile ->
// The task's own option, read as it runs: the last word of whatever configured it.
compile.doFirst('verifyNativeImageIndy', new VerifyNativeImageIndy())
Provider<Boolean> indyDisabled = project.provider {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run compileGroovy with the configuration cache, with indy true at configuration time, and a doFirst that sets indy to false before the verifier runs. The stored provider keeps the earlier value, so compilation proceeds with classic call sites. The previous check read the live option and rejected the task. Read the option when the verifier runs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — fixed in d5b84a7. When task is a GroovyCompile, VerifyNativeImageIndy.execute now reads ((GroovyCompile) task).groovyOptions.optimizationOptions.get('indy') live at execution time and only falls back to the captured Provider<Boolean> for non-GroovyCompile wrapper tasks. I added a --configuration-cache regression test covering both cache store and cache reuse when an earlier doFirst flips indy to false.

void execute(Task task) {
GroovyCompile compile = (GroovyCompile) task
if (compile.groovyOptions.optimizationOptions.get('indy') == Boolean.FALSE) {
if (Boolean.TRUE == indyDisabled.getOrNull()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forward the verifier from a GroovyCompile task with indy false to another with indy true. The verifier reads the source task and names the receiving task in the error, so a valid compile is rejected. Reversed flags let a compile through that should fail. Check the task that is running.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d5b84a7 — when VerifyNativeImageIndy.execute receives a GroovyCompile, it checks the receiving task's own live indy option and reports task.path. I added a regression test forwarding the verifier across GroovyCompile tasks in both directions (indy=false -> indy=true and indy=true -> indy=false).

@codeconsole

Copy link
Copy Markdown
Contributor Author

@sbglasius @jamesfredley Thanks for the thorough reviews! I pushed d5b84a7 addressing all points:

  • Updated VerifyNativeImageIndy to read the live indy optimization option from task whenever task instanceof GroovyCompile (handling both execution-time doFirst mutations under --configuration-cache and forwarding to another GroovyCompile), falling back to the captured Provider<Boolean> and sourceTaskPath for non-GroovyCompile wrapper tasks so errors name :compileGroovy.
  • Updated the VerifyNativeImageIndy Javadoc to reflect the captured fields and behavior.
  • Added tests for cross-GroovyCompile forwarding, wrapper task source path reporting, and --configuration-cache store + reuse with an execution-time doFirst mutating indy.

@github-actions
github-actions Bot dismissed sbglasius’s stale review December 4, 2026 15:49

Dismissed automatically: the pull request changed after this approval, from b234ccd to d5b84a7.

@codeconsole
codeconsole requested a review from sbglasius December 4, 2026 16:04

@jdaugherty jdaugherty left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reproduced the bug: with the production change reverted, the new runForwardedVerifyAction spec fails and the rest of GrailsNativeImageDefaultsSpec passes. With the fix all 15 pass, including the configuration-cache store and reuse case. The verifier no longer casts the task, reads the running GroovyCompile's live option, and falls back to the captured Provider and source path for a wrapper task.

Not blocking: the wrapper-task path is not exercised under --configuration-cache, only the GroovyCompile path is. A variant of the fixture would cover it.

@testlens-app

This comment has been minimized.

@codeconsole
codeconsole merged commit 61180f8 into apache:9.0.x Dec 4, 2026
5 of 19 checks passed
jdaugherty added a commit that referenced this pull request Dec 5, 2026
Brings 9.0.x's #16908, #17317 and #17319, 8.0.x's #16720, #16559, #16940, #16976, #17312,
#17315 and #17318, and the merge of 7.2.x that came up through 8.0.x and 8.1.x
(7b371cb): #17058, #17193, #17046, #17078, #16986, #17292 and #17307, the layout, view
and template name checks, and the SiteMesh 3 layout name check.

No conflicts. As #17316 and #17317 did on their branches, the GSP Spring Boot script
example grabs the version this branch publishes, 9.1.0-SNAPSHOT.
jdaugherty added a commit that referenced this pull request Dec 5, 2026
Brings the merge of 9.0.x into 9.1.x (950aa9a): 9.0.x's #16908, #17317 and #17319,
8.0.x's #16720, #16559, #16940, #16976, #17312, #17315 and #17318, and 7.0.x's #17058,
#17193, #17046, #17078, #16986, #17292 and #17307, the layout, view and template name
checks, and the SiteMesh 3 layout name check.

No conflicts. As #17316 and #17317 did on their branches, the GSP Spring Boot script
example grabs the version this branch publishes, 10.0.0-SNAPSHOT.
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.

4 participants