Repository navigation
Fix Groovy compilation on Gradle 9.7 and upgrade to 9.7.1 - #16114
Conversation
`configureGroovyCompiler` assigned `groovyOptions.configurationScript` from a
`doFirst` on each GroovyCompile task. Gradle finalizes task properties before
any task action runs, so from Gradle 9.7 — where GroovyCompileOptions became a
lazy property — every Groovy compilation fails:
Execution failed for task ':compileGroovy'.
> The value for task ':compileGroovy' property
'groovyOptions.configurationScriptFile' is final and cannot be changed
any further.
Assigning the property during configuration is not enough on its own: Gradle
then treats the script as an input file that must exist before the compile task
runs, which fails on a clean build because `doFirst` runs after input
validation. So the combined script is now produced by a dedicated task that the
compile task depends on.
That task is marked `doNotTrackState`, which keeps the property that motivated
the original `doFirst`: generating the script needs the resolved compile
classpath, and declaring it as an input would pull the runtimeClasspath into the
task's up-to-date check. The script is cheap to build, so it is simply
regenerated on every build.
Wiring moves to `afterEvaluate` so a `configurationScript` set by the build
script is already in place and gets folded into the combined script rather than
clobbered — the merge the old execution-time read performed. Task names are read
via `TaskCollection.names`, which does not realize the tasks.
Verified against a multi-project Grails 8 application on both Gradle 9.6.1 and
9.7.0: full `bootJar`, and `clean` plus compilation in a single invocation.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 8.0.x #16114 +/- ##
==================================================
+ Coverage 54.7109% 54.7201% +0.0092%
- Complexity 20420 20465 +45
==================================================
Files 2101 2104 +3
Lines 100978 101089 +111
Branches 17907 17925 +18
==================================================
+ Hits 55246 55316 +70
- Misses 37863 37896 +33
- Partials 7869 7877 +8
🚀 New features to boost your workflow:
|
Moves grails-core's own build onto 9.7.0: `.sdkmanrc`, `gradleToolingApiVersion`, and the wrapper for every Gradle build in the repository — root, build-logic, grails-gradle, grails-forge, end-to-end — plus the grails-shell-cli gradle-sample fixture. The shared wrappers were regenerated with `gradle -p gradle-bootstrap`; the gradle-sample fixture, which bootstrap does not reach, was refreshed from the same output so the launcher scripts and wrapper jar stay byte-identical everywhere. `end-to-end/legacy-g7-command-plugin` deliberately stays on Gradle 8.14.5, the version Grails 7 pins for that fixture. The wrapper task regenerates the properties files from scratch, so the "keep this synced" checklist comments were restored afterwards.
Applications created by the forge and by the profile CLIs now get a 9.7.0 wrapper instead of 9.6.0. For the forge, that means the `gradleWrapperProperties` template plus the three binaries `Gradle.java` copies onto the generated project — `gradlew`, `gradlew.bat`, and `gradle/wrapper/gradle-wrapper.jar`. For the profile CLIs, only the `base` and `profile` skeletons carry wrapper assets; `web`, `rest-api`, and `plugin` inherit them from `base` through `profileRuntimeApi`, and `web-plugin` / `rest-api-plugin` chain through those, so every application type picks the new wrapper up. Generated applications can only move to 9.7 together with the compiler config script fix earlier in this branch — without it every Groovy compilation in a Grails project fails on Gradle 9.7.
jamesfredley
left a comment
There was a problem hiding this comment.
I reproduced three lifecycle failures against this exact head. Inline comments include the commands/observable failures and focus only on correctness gaps.
| // Wiring happens after evaluation so a configurationScript set by the build script is already | ||
| // in place and gets folded into the combined file rather than clobbered. Names are read via | ||
| // TaskCollection.names, which does not realize the tasks. | ||
| project.afterEvaluate { |
There was a problem hiding this comment.
This one-time snapshot regresses the previous live configureEach behavior. A GroovyCompile registered from a later projectsEvaluated callback is absent from names and receives no generator/configuration script; I reproduced this against this head (LATE_GROOVY_UNCONFIGURED=true, with no generateLateGroovyGrailsCompilerConfig task). Please retain live wiring without registering a generator from inside the task-container callback (for example, a deferred task rule plus string dependsOn) and add a late-task TestKit case.
There was a problem hiding this comment.
Confirmed and fixed in 8b8d063. TaskCollection.names is an immutable snapshot, so a GroovyCompile registered after the afterEvaluate got no generator and no configuration script, silently.
Generator tasks are now registered from sourceSets.configureEach, which is live — source sets are what create GroovyCompile tasks, so a source set added from projectsEvaluated is covered.
One correction on the suggested remedy: a task rule plus string dependsOn does not work. Rules are not consulted when resolving a dependsOn name — the build fails at graph construction with Task with name 'generateCompileGroovyGrailsCompilerConfig' not found. And registering the generator from inside the task-container callback is what the snapshot was avoiding in the first place: it throws TaskCreationException: Could not create task ':compileGroovy'. Hooking the source-set container sidesteps both.
Test: GrailsGroovyCompilerConfigSpec — a GroovyCompile registered after the project is evaluated still gets a generator.
| // the inputs to this task would effectively be the runtimeClasspath, dependency | ||
| // problems can arise if another task changes the runtimeClasspath. Generating the | ||
| // script is cheap, so skip state tracking and regenerate on every build instead. | ||
| t.doNotTrackState('Depends on the resolved compile classpath; cheap to regenerate') |
There was a problem hiding this comment.
doNotTrackState suppresses validation but does not establish execution ordering. The doLast calls getGroovyCompilerScript, which scans compileTask.classpath, while this generator has no dependency on tasks producing those classpath entries. I forced a classpath producer to run after the generator on a clean build; the generator omitted grails.gorm.annotation, then compileGroovy failed with unable to resolve class CreatedDate. Please model the classpath/base script as inputs and depend on their producer tasks.
There was a problem hiding this comment.
Right that doNotTrackState establishes no ordering — the generator declared no dependencies at all while its action resolves compileTask.classpath and reads jar entries from it. Fixed in 8b8d063: it now depends on the classpath's own build dependencies.
I used dependsOn rather than declaring the classpath as an input, because modelling it as an input reintroduces exactly what doNotTrackState is there to prevent — it drags the runtimeClasspath into the up-to-date check. dependsOn gets the ordering without the tracking.
For the record on severity: I could reproduce the missing edge, but not the failure. In the natural task graph Gradle schedules the producing jar before the generator, and the two probed classes normally come from external jars already in the module cache. That matches your note that you had to force the ordering. Still worth closing — it was a real latent hazard.
Test: GrailsGroovyCompilerConfigSpec — the generator runs after the tasks that produce the compile classpath.
| combinedFile.write(combinedScripts) | ||
| c.groovyOptions.configurationScript = combinedFile | ||
| compileTask.configure { GroovyCompile c -> | ||
| userConfigurationScript[0] = c.groovyOptions.configurationScript |
There was a problem hiding this comment.
This capture/replace is not stable for later configuration. When a user assigns configurationScript from a later projectsEvaluated callback, that assignment overwrites the combined script after this action. Reproduced result: the user's LocalDate import worked, but the generated Grails CreatedDate import disappeared and compilation failed. Please capture the final configured script at a graph-safe point (or wire it provider-first) and cover a later-callback assignment in TestKit.
There was a problem hiding this comment.
Confirmed and fixed in 8b8d063. Capturing during afterEvaluate meant an assignment from any later callback simply overwrote the combined file and the Grails imports disappeared with no error.
Capture and assignment now happen at taskGraph.whenReady — the last point before execution and after every configuration callback has run, so the user's final value is what gets folded in. The property is still assignable there on 9.7.
Scope note for anyone reading later: the ordinary path — assigning configurationScript directly in the build script — was already merging correctly. Only assignment from a later callback was affected.
Test: GrailsGroovyCompilerConfigSpec — a configurationScript assigned from a later callback is folded in, not clobbered.
Moving the compiler configuration script off a `doFirst` traded three execution-time guarantees for configuration-time snapshots. Each one is restored: Late-registered compile tasks are wired again. `TaskCollection.names` read inside `afterEvaluate` is an immutable snapshot, so a `GroovyCompile` created later — by a source set added from `projectsEvaluated`, or from another plugin's `afterEvaluate` — got no generator and no configuration script, silently. Generator tasks are now registered from `sourceSets.configureEach`, which is live. They cannot be registered from a `GroovyCompile` configuration action: mutating the task container while it is being configured throws `TaskCreationException`, which is what the snapshot was working around. The generator is ordered against the compile classpath it reads. `doNotTrackState` suppresses up-to-date checking but establishes no ordering, and the generator declared no dependencies at all while its action resolves `compileTask.classpath` and reads jar entries from it. It now depends on the classpath's own build dependencies, so the probes see the artifacts. `dependsOn` rather than an input declaration, to keep the runtimeClasspath out of the up-to-date check — the property `doNotTrackState` was added to protect. A `configurationScript` assigned after wiring is folded in rather than dropped. The user's script was captured during `afterEvaluate`, so an assignment from any later callback simply overwrote the combined file and the Grails imports disappeared with no error. Capture and assignment now happen once the task graph is ready, the last point before execution, after every configuration callback has run. The capture map is a per-project instance field, not static, so a script cannot leak into a later build in the same daemon.
|
Thanks — all three were real. Fixed in 8b8d063 with a regression test each in Common root cause: the fix had to move from execution-time reads to configuration-time snapshots, because Gradle 9.7 forbids assigning
|
|
@codeconsole Looking back the code history: we used a separate task previously and the commit message where we reverted this was: How does this change then solve this? |
|
Do we know why the compile configuration can no longer be changed at execution? This seems like an artificial limitation by Gradle and I'm wondering if we should instead open a bug ticket on this. |
…scope
`GroovyCompileOptions.getConfigurationScript()` is annotated
`@ReplacedBy("configurationScriptFile")`: the `File` accessor is superseded by a
`RegularFileProperty`. Assign through that property instead. The eager setter
delegates to it, so a script a build assigns either way is still picked up.
The ordering test now also asserts what the generator must *not* be coupled to. An
earlier task-based design declared `configurations.runtimeClasspath` as a task input,
which pulled the runtime classpath into the generator's up-to-date check and produced
task dependency errors when it changed (9a529d1). This generator declares no
inputs at all and depends only on the compile classpath's build dependencies, which
`compileGroovy` already depends on, so the runtime classpath enters neither the
dependency chain nor an up-to-date check.
…asspath `isClassOnClasspath` opened jars on the compile classpath to decide whether to add the `grails.gorm.annotation` and `grails.plugin.scaffolding.annotation` star imports. That single probe is what forced every other awkward property of this wiring: the script could only be built at execution time, which is why it was computed in a task action, why the task opted out of state tracking, and why it needed an ordering edge to whatever produced the classpath. The probe bought nothing. A star import of a package that is not on the classpath contributes no classes and is not an error in Groovy — verified on 5.0.8 for both dynamic and static compilation — so the imports are now added unconditionally when `importGrailsCommonAnnotations` is set, exactly as `jakarta.validation.constraints` already was. With the classpath out of the picture: - The generator takes the finished script as a single input property and writes it. It is up-to-date checked and cacheable rather than `doNotTrackState`, and needs no dependency on the compile classpath, so no configuration enters its dependency chain or its up-to-date check. - The script is built while the compile task is configured, which restores an input declaration lost when it moved into a task action: `GrailsPluginGradlePlugin` bakes the project version and name into compiled classes as AST metadata and registers them as inputs of the compile task. Since 7950482 that ran too late to take effect, so changing a plugin's version left the stamped metadata stale. Regression tests cover all four properties; each fails against 7950482.
A build may point `configurationScript` at a file another task generates. Taking the property over meant that producer was no longer ordered against the generator, so on a clean build the generator read the file before it existed and the build's own script was silently dropped from the combined output — present only from the second build onwards, off a stale file. The generator now depends on that producer. Task graph construction runs before the property is taken over, so the property still carries whatever the build set, and with it the producing task. Wrapping it in a FileCollection is what asks Gradle for the producer: depending on the property directly tries to convert the file itself into a task, and the collection has to be guarded on `present` because building one from a property with no value fails while dependencies are being resolved.
The script was written by an ad-hoc task configured with `inputs.property` and `outputs.file` in the plugin. It is now a `GrailsCompilerConfigScriptTask` with an `@Input Property<String>` and an `@OutputFile RegularFileProperty`, matching how the rest of this plugin's tasks are written and making the contract legible from the task rather than from its registration site. Behaviour is unchanged; the input property is now named for the task's own property. Tests added for two properties that were not covered: one generator per source set with a real up-to-date check (unchanged build is UP-TO-DATE, changed imports are not), and that the wiring stores and reuses a configuration cache entry.
…pt' into fix/gradle-97-groovy-config-script
Bumps the patch release across every location the version-sync rule reaches: `.sdkmanrc`, `gradleToolingApiVersion`, and all eight main-line `gradle-wrapper.properties`, including the forge and profile skeletons that generated applications inherit. 9.7.1 leaves the wrapper jar and the `gradlew` scripts untouched, so this is a `distributionUrl` change only. `end-to-end/legacy-g7-command-plugin` stays on Gradle 8.14.5, the version Grails 7 pins for that fixture. SDKMAN has not indexed 9.7.1 yet, so `sdk env` will report it as unreleased until it does; the wrappers are unaffected because they fetch the distribution directly.
| @@ -2256,7 +2362,278 @@ resolved unambiguously before can become ambiguous. | |||
| Removing the packages from `grails.spring.bean.packages`, or the stray classes from those packages, restores | |||
| the previous set of beans. | |||
|
|
|||
| ==== 45. `importJavaTime` Removed | |||
| ==== 45. GORM API Resolution Moves to a Registry | |||
There was a problem hiding this comment.
Where does all these lines come from and why are they related to this PR? Seems odd.
There was a problem hiding this comment.
They come from 8.0.x, not this PR. Section 45 arrived in #16066 (2926a0f644), and 46/47 likewise predate this branch — all three sit at this same line on upstream/8.0.x today. The branch picked them up when it was brought up to date.
This PR's net change to the file is 39 added lines — section 48, importJavaTime Removed:
git diff upstream/8.0.x HEAD -- grails-doc/src/en/guide/upgrading/upgrading80x.adoc
1 file changed, 39 insertions(+)
The Files changed tab shows that one hunk. "Changes since your last review" will include the 8.0.x merge, since the approval predates it.
based on upstream merged changes
…vy-config-script # Conflicts: # grails-doc/src/en/guide/upgrading/upgrading80x.adoc
…vy-config-script # Conflicts: # grails-doc/src/en/guide/upgrading/upgrading80x.adoc
matrei
left a comment
There was a problem hiding this comment.
AI review:
Review Findings
The current head 7714cded41 addresses the previously reported lifecycle issues, but the following regressions remain.
[P2] Standalone GroovyCompile tasks lose Grails compiler configuration
File: grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy:306-312,335-339
Generator tasks are registered only from SourceSetContainer entries:
sourceSets.configureEach { SourceSet sourceSet ->
registerGroovyCompilerConfigGenerator(project, sourceSet.getCompileTaskName('groovy'))
}The plugin still configures every GroovyCompile task at lines 314-327, but a standalone task that is not associated with a source set never gets a corresponding generator. The whenReady callback then skips it because the generated task name is absent.
This regresses the previous behavior, where the doFirst compiler-script wiring was attached to every GroovyCompile task. A manually registered task such as:
tasks.register('compileCustomGroovy', GroovyCompile) {
source('src/custom/groovy')
destinationDirectory.set(layout.buildDirectory.dir('classes/custom'))
classpath = sourceSets.main.compileClasspath
}will not receive starImports, importGrailsCommonAnnotations, a plugin's compiler metadata, or a user-provided configurationScript merged with the Grails script. This is particularly significant for GrailsPluginGradlePlugin, whose override adds projectVersion, projectName, and isPlugin metadata to the compiler script.
Please preserve compiler-script wiring for standalone GroovyCompile tasks, while avoiding task-container mutation during task configuration. Add a TestKit regression test for a standalone task.
[P2] Missing user compiler scripts are silently ignored
File: grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy:391-394
The combined script reads a captured user script only when the file exists:
String configuredScript = userScript?.exists() ? (userScript.text?.trim() ?: null) : nullAt lines 345-352, the plugin replaces the original configurationScriptFile with the generated combined file. Therefore, Gradle no longer validates the originally configured user file. If a build configures a nonexistent script:
tasks.named('compileGroovy', GroovyCompile) {
groovyOptions.configurationScript = file('missing-config.groovy')
}the generator silently emits only the Grails script and compilation proceeds without the requested compiler configuration. Before this change, the execution-time .text access failed for a missing file, making a typo or deleted file visible to the user.
Please retain the producer-task support while ensuring that an explicitly configured user script which remains unavailable fails the build instead of silently disabling compiler behavior. Add coverage for a missing configured script.
Verification
The following focused checks passed:
./gradlew :grails-gradle-plugins:test --tests 'org.grails.gradle.plugin.core.GrailsGroovyCompilerConfigSpec' --no-daemon./gradlew :grails-gradle-plugins:test --no-daemon./gradlew :grails-gradle-plugins:compileGroovy :grails-gradle-plugins:compileTestGroovy --no-daemon
The wrapper audit also confirmed the intended Gradle 9.7.1 mainline locations and the intentional Gradle 8.14.5 legacy fixture split.
Two gaps found in review of the generator wiring. A GroovyCompile that no source set owns, one a build registers directly, got no generator, so it compiled without the Grails star imports, a plugin's AST metadata, and the combined script. The generator is now created on demand when the compile task's dependencies are resolved, which happens while the task graph is built and outside any task configuration action, so the container is mutable there. The source-set hook stays for the tasks it already covered. The whenReady capture walks the tasks about to run instead of realizing every GroovyCompile in the project. A configurationScript pointing at a file that does not exist was dropped silently: the compile task's own property had been replaced with the combined file, so Gradle's validation no longer saw it, and the generator read nothing. The build's script is now an optional @InputFile of the generator rather than text folded into the @input string, so Gradle fails the build naming the missing file before the generator runs.
…pt' into fix/gradle-97-groovy-config-script
|
Both confirmed and fixed in 818d22b, each with a regression case in Standalone Test: a GroovyCompile that no source set owns is wired like the source set ones — a directly registered Missing user script. The build's script is now an Producer support is unchanged: the ordering edge to the task that writes the script is still declared, and the classpath decoupling assertions still hold ( Test: a configurationScript that does not exist fails the build instead of being dropped. |
✅ All tests passed ✅🏷️ Commit: 5684ed1 Learn more about TestLens at testlens.app/docs. |
|
I originally raised a concern on this PR in this comment. From what I can tell, it was never addressed or answered, yet this change was merged. I'm frustrated this was merged. |
|
From what I recall of the original problem: Add a secondary task dependency on compileGroovy, by adding an intermediate task, now that task dependency must also depend on compileGroovy. This has caused issues in our builds enough for us to revert to a |
|
@jdaugherty I understand the concern about reintroducing task-ordering failures. I should have followed up with you to establish whether the change covered your actual build wiring before this was merged. My earlier explanation addressed the runtime-classpath dependency in the old implementation: the merged generator no longer reads either classpath. That addresses that particular dependency, but does not settle every ordering case you described. I have now reproduced a narrower case in an execution-level test: a build that assigns a plain I'm preparing a follow-up with that regression test and upgrade documentation for the provider wiring. It keeps the generator independent of unrelated compilation prerequisites; copying all of those dependencies could introduce cycles. Returning to the old Could you share the actual task registration and |
…asspath The task-based wiring that 9a529d1 replaced with a doFirst declared runtimeClasspath as an input of the generator task, so any task whose output reached the runtime classpath became a transitive dependency of compileGroovy. A post-compile step that feeds the runtime classpath, such as asset-pipeline output or the exploded plugin directory, then closed a cycle. That is the concern raised on apache#16114. The generator introduced there takes its script from grails { } state and declares no classpath input, so that edge no longer exists. This test recreates the scenario: a task that runs after classes and puts its output on the runtime classpath via runtimeOnly files(task). It asserts the generator does not depend on that task, and that compileGroovy and the producer schedule together without a cycle.
Apache Grails published 8.0.0-RC1 on 2026-09-23. Like M6 before it, the artifacts are in the ASF staging group only while the release vote runs, so the TEMP staging-repository entries in build.gradle stay for now and the comments are retargeted at RC1. Spring Boot stays at 4.1.1 (RC1's BOM manages the same version); Groovy follows the BOM to 5.1.3 and the cloud.wondrify asset-pipeline plugin to its 5.2.0-RC1 release, which is already on Maven Central. The RC1 Grails Gradle plugin is built against Gradle 9.7 (apache/grails-core#16114): on the 9.6.0 wrapper `gradlew assemble` dies with NoSuchMethodError on GroovyCompileOptions.getConfigurationScriptFile() returning a RegularFileProperty. Move the wrapper to 9.7.1, the current release. RC1 hands multipart handling to Spring Boot's auto-configuration (apache/grails-core#16040): the grails.controllers.upload.maxFileSize / maxRequestSize keys are gone, and an application that still sets them aborts at startup with a migration message. Move bbb-web's limits to spring.servlet.multipart.max-file-size / max-request-size with the same values. Without an explicit setting, Boot's defaults (1 MB per file, 10 MB per request) would silently cap presentation and caption uploads; BigBlueButton's own per-presentation cap (maxFileSizeUpload, enforced by ParamsProcessorUtil) is unchanged. Also in RC1 (apache/grails-core#16149) the _method override moved from a servlet filter into the dispatcher and is off by default, so the disabled hiddenHttpMethodFilter registration in resources.groovy is now redundant. It still compiles and stays inert, so it is left alone here. Verified with a package build in the grails-8 build image, deployed to a 4.0 dev container: startup in 4.4 s without warnings, checksummed create/getMeetingInfo/end round-trip, a 5.3 MB presentation upload through the client (above Boot's default per-file limit), and the api, learningdashboard, presentation and parameters Playwright suites. Every remaining failure in those suites reproduces with the same signature on the pre-upgrade Grails 7.0.12 package (screenshot drift, the @flaky external-video tests, a test needing maskTagThreshold > 0, and the predefined breakout groups tests).
Problem
GrailsGradlePluginassignedgroovyOptions.configurationScriptfrom adoFirst. Gradle finalizes task properties before any task action runs, so from Gradle 9.7 — whereGroovyCompileOptionsbecame a lazy property — every Groovy compilation in every Grails project fails:There is no user-side workaround and no Gradle opt-out flag.
Fix
A
GrailsCompilerConfigScriptTaskproduces the combined script, and the compile task depends on it. The script is built fromgrails { }state and reads no classpath, so the task takes the Grails half as one@Inputstring and the build's ownconfigurationScript, when there is one, as an@InputFile: up-to-date checked, validated by Gradle when that file is missing, and it stores and reuses a configuration cache entry. EveryGroovyCompileis covered — the source-set ones get a generator up front, and one a build registers directly gets it when its dependencies are resolved.GrailsGroovyCompilerConfigSpeccovers the lifecycle: aGroovyCompileregistered after the project is evaluated, one no source set owns, aconfigurationScriptthe build assigns from any configuration callback, one produced by another task, one that does not exist, a generator per source set, and a plugin's version and name staying inputs of its compile task.Behaviour changes
Both are in the star imports, which stay opt-in —
importGrailsCommonAnnotationsandstarImportsdefault to off.importGrailsCommonAnnotationsnow addsgrails.gorm.annotationandgrails.plugin.scaffolding.annotationwithout first probing the compile classpath. A star import of a package that is not on the classpath contributes no classes and is not an error in Groovy.importJavaTimeis removed. Groovy 5 importsjava.timeby default, so it did nothing on Grails 8. A build that sets it fails withCould not set unknown property 'importJavaTime'; drop the line.Both are documented in the Grails 8 upgrade guide, section 53.
Gradle 9.7.1
Grails builds on 9.7.1:
.sdkmanrc,gradleToolingApiVersion, and the wrapper for root,build-logic,grails-gradle,grails-forge,end-to-end, plus thegrails-shell-cligradle-sample fixture.end-to-end/legacy-g7-command-pluginstays on Gradle 8.14.5, the version Grails 7 pins for that fixture.Applications created by the forge and the profile CLIs get a 9.7.1 wrapper as well. They can only move to 9.7 together with the fix above; without it the first
compileGroovyfails.