Repository navigation
9.0 (fix): capture indy Provider in VerifyNativeImageIndy instead of casting Task - #17319
Conversation
|
We should put this change in 8.0.x as it's really a bug fix. |
|
|
sbglasius
left a comment
There was a problem hiding this comment.
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
VerifyNativeImageIndystill 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 oncompileGroovy. Capturingcompile.pathwhen 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
left a comment
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
|
@sbglasius @jamesfredley Thanks for the thorough reviews! I pushed d5b84a7 addressing all points:
|
jdaugherty
left a comment
There was a problem hiding this comment.
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.
This comment has been minimized.
This comment has been minimized.
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.
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.
Summary
GrailsGradlePlugin.VerifyNativeImageIndyto accept aProvider<Boolean> indyDisabledcaptured at task configuration time (project.provider { compile.groovyOptions.optimizationOptions.get('indy') == Boolean.FALSE }) instead of casting theTaskargument toGroovyCompileinsideexecute(Task).GrailsNativeImageDefaultsSpecverifying that theverifyNativeImageIndydoFirstaction executes cleanly against a plainDefaultTaskboth when invokedynamic is enabled (passes) and when disabled late viaafterEvaluate(fails with the expected message).Motivation
Plugins that wrap or replace
compileGroovywith a customDefaultTask(such asjdaugherty/incremental-groovy-compile) and forwardcompileGroovy'sdoFirstactions fail withClassCastException: ... cannot be cast to org.gradle.api.tasks.compile.GroovyCompilewhenVerifyNativeImageIndy.execute(Task)casts its task argument. Capturing aProvider<Boolean>preserves lazy evaluation for lateafterEvaluateoverrides while avoiding theGroovyCompilecast and remaining configuration-cache safe.I targeted
9.0.xbecauseVerifyNativeImageIndywas introduced on9.0.x.Verification
./gradlew :grails-gradle-plugins:codenarcMain :grails-gradle-plugins:test --tests "*GrailsNativeImageDefaultsSpec"ingrails-gradle/(all 13 tests passed, CodeNarc clean).