Repository navigation
feat: enable Groovy invokedynamic by default on Grails 9 - #16165
Conversation
Grails 7 turned indy off because Groovy 4 paid a 2-8x penalty (#15293). Grails 9 is on Groovy 6, where microbenchmarks were already positive and app-level results were flat to slightly negative. Make indy the default so generated apps match Groovy 6's preferred dispatch. Opt out with grails { indy = false }. Non-indy still needs groovy-callsite, which the BOM already manages. Framework modules honor -PgrailsIndy so CI and JMH can still A/B both modes. Assisted-by: claude-code:claude-opus-5
There was a problem hiding this comment.
Pull request overview
This PR flips the default Groovy invokedynamic (“indy”) setting to enabled for Grails 9 builds, aligning generated applications with Groovy 6’s preferred dynamic dispatch mode while preserving an opt-out path and CI/framework-module toggling.
Changes:
- Set the
grails { indy }convention default totrueand update plugin logging accordingly. - Add build-logic support for
-PgrailsIndyto control indy in framework modules, including addingorg.apache.groovy:groovy-callsitewhen indy is forced off. - Add/extend tests and documentation covering the new default and the opt-out configuration.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| grails-gradle/plugins/src/test/groovy/org/grails/gradle/plugin/core/GrailsExtensionSpec.groovy | Adds tests asserting indy default-on and opt-out behavior in the Gradle extension. |
| grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy | Changes indy default handling to enabled and updates informational logging. |
| grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsExtension.groovy | Sets the indy convention default to true and updates associated Javadoc. |
| grails-doc/src/en/guide/introduction/whatsNew.adoc | Documents indy being enabled by default and how to disable it. |
| build-logic/plugins/src/test/groovy/org/apache/grails/buildsrc/CompilePluginIndySpec.groovy | Adds coverage for -PgrailsIndy behavior in framework-module compilation configuration. |
| build-logic/plugins/src/main/groovy/org/apache/grails/buildsrc/CompilePlugin.groovy | Honors -PgrailsIndy for framework modules and adds groovy-callsite when indy is disabled. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
JMH Shard PairingComplete shard pairs used: 2 JMH Benchmark ReportRegressions: 0
Group geometric means are descriptive only, not verdicts.
Per-benchmark results
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 9.0.x #16165 +/- ##
==================================================
+ Coverage 60.9935% 60.9973% +0.0038%
+ Complexity 26643 26637 -6
==================================================
Files 2249 2249
Lines 111561 111577 +16
Branches 20207 20224 +17
==================================================
+ Hits 68045 68059 +14
- Misses 34532 34553 +21
+ Partials 8984 8965 -19
🚀 New features to boost your workflow:
|
-PgrailsIndy=false is how CI compiles applications without indy. Wiring
that property through CompilePlugin forced every framework module onto
classic callsites and added org.apache.groovy:groovy-callsite with no
version, so those jobs failed with "Could not find groovy-callsite:.".
Leave framework compilation on Groovy's default. App indy remains
controlled by grails { indy }. Clarify the docs so default-on does not
read like a required setting.
Assisted-by: claude-code:claude-opus-5
Indy Whiplash?I agree with this change, but I wonder if we should consider turning indy on in the final release of 8? I think it is counter intuitive to go against Groovy defaults and turn it opposite to normal compiler behavior. At the very least we should consider not changing downstream plugin behavior and perhaps enforce plugins indy true? The following should be fully understood prior to 8.0.0:
Current state of Grails 8 indy OFF (29): indy ON (17, Groovy 5 default): |
MiscSpec is identical to 8.0.x and passed on 9.0.x when the plugin defaulted to indy=false. With indy on by default, Map-as-FilterChain and session[name] are fragile Groovy dispatch. Use a real FilterChain and HttpSession.getAttribute instead. Assisted-by: claude-code:claude-opus-5
|
@codeconsole only holdup is Groovy 5 indy is not as fast as Groovy 6 indy. |
MiscSpec failed only when the security plugin compiled with indy on.
The session dump already contained Username=admin. with(auth) {
contains(...) } does not dispatch to String.contains under Groovy 6
indy. Direct pageSource.contains already passed. Call contains on the
string instead and snapshot pageSource once per assertion block.
Assisted-by: claude-code:claude-opus-5
The same dispatch bug as MiscSpec. ACL and UI functional specs call
with(pageSource) { contains(...) }, which does not hit String.contains
when compiled with invokedynamic. Use pageSource.contains instead.
Assisted-by: claude-code:claude-opus-5
UserSimpleSpec failed because with(page.rolesTab) { hasEnabledRole(...) }
dispatched to Geb DefaultNavigator under Groovy 6 invokedynamic. Call
the tab methods on page.rolesTab instead.
Assisted-by: claude-code:claude-opus-5
App-level indy vs callsite (local A/B)Ran the existing Machine: Windows, JDK 21, warmup 80 / samples 300 / forks 2.
This matches the earlier story: app-level is flat to slightly negative, not the old 2-8x Groovy 4 penalty. A follow-up |
jdaugherty
left a comment
There was a problem hiding this comment.
let's remove teh mass test changes that removed the with usage in tests?
Take #16178's CompilePlugin -PgrailsIndy toggle and flip the default to true so Grails 9 / Groovy 6 framework modules match app-level grails { indy } (already default-on). CI can still pass -PgrailsIndy=false. Assisted-by: Sisyphus:grok-4.6
|
Brought in #16178 via the 8.0.x -> 8.1.x -> 9.0.x merge-up (#16318, #16319).
|
9.0.x is on Groovy 6.0.0, which carries the AOT link mode and ships its own native-image configuration, not 6.0.0-beta-2. Invokedynamic is on for the library modules only: the plugin modules, including grails-gsp, grails-sitemesh3 and grails-cache from the web starter, still follow the Grails Gradle plugin's default until apache#16165 changes it.
CompilePlugin and its spec take 9.0.x's version: since a963c8b the library modules compile with invokedynamic on regardless of -PgrailsIndy, because they do not carry groovy-callsite, which already covers this branch's "default on for published modules" change. gradle.properties takes 9.0.x's 3G daemon and drops the Spock version-check opt-out that the move to Spock 2.5-groovy-6.0 retired.
…ts it Gradle passes no indy option to the Groovy compiler unless a build sets one, and the compiler then uses its own default, which is invokedynamic on Groovy 5 and 6. Grails 7 and 8 have to override that with false for performance (#15293); Grails 9 does not, so instead of defaulting grails { indy } to true and writing it onto every GroovyCompile task, the property is now unset by default and the plugin only applies a value the application set. That stops the plugin from replacing an indy option a build script puts on its own compile task, and the native-image hook no longer needs to set an indy convention, since an image's need for invokedynamic is the compiler's default. GrailsNativeImageDefaultsSpec hard-coded the Grails 8 default of false for an application without an image; it and its fixtures now check that no indy option is set on the compile task. GrailsIndySpec covers the unset default and both explicit values through a TestKit build. What's New describes the change without the internal build details, and the 9.0 upgrade guide notes it for applications coming from Grails 8.
Reverts ccce1ba, 0017bc6 and 782b00f, which replaced Spock with(target) { ... } blocks with explicit target.method() conditions in 21 security functional specs because a call such as contains(...) inside with(pageSource) did not reach String.contains when compiled with invokedynamic. That was Spock 2.4's Groovy 5 build running on Groovy 6. 9.0.x now uses Spock 2.5-groovy-6.0, and the patterns pass when compiled with indy: a probe GebSpec ran with(pageSource) { contains(..); !contains(..) } and with(page) { username.text == ..; !accountLocked.checked }, and a plain Specification with its own truthy contains(String) ran the same negative condition, which would fail if the call reached anything but the String. The specs are identical to 9.0.x again.
…ndy off
A native image needs invokedynamic: a classic call site defines a class
at run time, which an image cannot do. Leaving indy at the compiler's
default removed the native-image hook's indy convention, so an
application that set grails { indy = false } built an image that failed
on its first dynamic call.
The hook is back as it was, setting the convention to true when GraalVM's
plugin is applied, which also overrides a compile task a build script set
to classic call sites, since the plugin applies the extension's value to
every Groovy compile task. After evaluation it throws, with the reason, if
the application set grails { indy = false } itself.
GrailsNativeImageDefaultsSpec covers both, the deployment guide's AOT
chapter documents it, and the 9.0 upgrade note mentions it.
The native image guard read only the extension, so a build script that set the indy compiler option to false on a compile task from its own afterEvaluate, which runs after the plugin's, kept classic call sites and built an image that failed on its first dynamic call. Each Groovy compile task of a project that applies GraalVM's plugin now checks its own option as it starts and fails with the reason; the fixture gains that late override and a spec for it, plus a row for an explicit indy = true. GrailsIndySpec now proves the premise from the bytecode: the fixture compiles a dynamic class and the class file carries invokedynamic call sites when indy is unset or true, and classic ones when it is false. The comments on the groovy-callsite dependencies in grails-common and the Forge CLI fixtures said Grails compiles without invokedynamic, which is no longer so; they now name the opt-out and CI's -PgrailsIndy=false lane. The upgrade note tells build logic that read grails.indy that it has no value unless set, and the AOT chapter's wording matches what the guard does.
Reverts 2cbd651, which replaced session[name] in the security functional test app's HackController with getAttribute, and the security taglib's Map-coerced FilterChain with a nested class, on the same "fragile dispatch under invokedynamic" diagnosis as the with() rewrites. Both compile with invokedynamic now and both dispatch correctly: with the original code restored, MiscSpec and DisableSpec of the misc test configuration and SecurityTagLibUnitSpec pass, so the files are identical to 9.0.x again. The nested class had also put a second copy of GrailsWebInvocationPrivilegeEvaluator's dummy chain inside a taglib artefact, where the artefact injectors sweep it.
grails-common declared org.apache.groovy:groovy-callsite as an api
dependency, so every Grails 9 application carried the module whether or
not it compiled classic call sites, which Grails 9 does not by default.
The dependency is gone: an application that sets grails { indy = false }
declares the module itself, at the version the Grails BOM manages, and
the Groovy compiler names it when it is missing. What's New, the 9.0
upgrade guide and the extension's javadoc say so.
CI's -PgrailsIndy=false lane compiles every source set of the Grails
plugin modules and example apps with classic call sites, so the shared
grails-extension-gradle-config script, which applies that flag, now
declares the module for each source set of such a project. The version
is read from the map in dependencies.gradle, applied to the root project
once in that lane as the build-logic builds apply it, because the ast
source set the Grails plugin gives every plugin project has no platform
on its configurations to supply one.
The Forge CLI test fixtures no longer need their own declaration: they
compile with invokedynamic like everything else.
The TestKit fixtures' Groovy sources that the previous commit's bytecode
and late-override features compile were left out of it; they are added.
…ites
The grails-developer skill gains a Groovy call sites section: Grails 9
compiles with invokedynamic and ships no groovy-callsite, so the default
is to remove the indy settings and the groovy-callsite dependency a
Grails 7 or 8 build carried, and classic call sites are offered as the
alternative: grails { indy = false } plus the dependency the application
declares itself, which a native image build refuses.
The gradle-developer skill records how this repository handles it: the
library modules always compile with invokedynamic, grails-common must not
declare groovy-callsite, the -PgrailsIndy=false lanes get the module from
grails-extension-gradle-config with the version read from
dependencies.gradle applied to the root, and Forge ignores the flag.
AGENTS.md states the dependency rule.
… testcontainers-spock With groovy-callsite gone from grails-common, the -PgrailsIndy=false lane failed in three ways. A test module compiled against a plugin module's test fixtures, now classic, failed to compile; the GSON view compiler, run with a classpath that no longer carried the module, failed to load a plugin's classes; and the Hibernate 7 specs failed to load TestcontainersExtension. The first two are the lane's: declaring the module only in the projects that apply grails-extension-gradle-config missed every other module that compiles or runs against them. The declaration moves to CompilePlugin, which every Groovy-compiling module applies now that the spring-security UI common module does too: in that lane it adds the module to every source set of every module, through a provider so the version is read once the build scripts have run, from the map in dependencies.gradle applied to the root project. It does so only in the build that was invoked: the property reaches the included builds too, and the Groovy 6 module on the Grails Gradle plugins' classpath, which runs on Gradle's own Groovy, broke configuration with a VerifyError in grails.util.Environment. The extension script keeps only the indy toggle. CompilePluginSpec covers the declaration and its absence. The third is not the lane's. testcontainers-spock is compiled with classic call sites, which Groovy 6 loads only with the module, whatever the application's own setting; Spock, Geb and the Asset Pipeline versions in use are not. The four modules that test with it declare the module as testRuntimeOnly next to it. What's New, the 9.0 upgrade guide, the developer and Gradle skills and AGENTS.md describe that case.
… only The previous commit skipped every included build when declaring groovy-callsite in the -PgrailsIndy=false lane, to keep the Groovy 6 module off the Grails Gradle plugins' classpath. That also skipped grails-core when Forge builds it as an included build, so Forge's classic lane failed to compile the GSON views as before. The skip now names the two builds whose code runs inside Gradle, build-logic and grails-gradle, by root project name; grails-core is injected wherever it is built. CompilePluginSpec covers both names.
…e in the classic lane The two Forge builds that run with -PgrailsIndy=false failed in the specs that generate an application and build it. The property reaches the included grails-core build, so the framework those applications consume from build/local-maven is compiled with classic call sites, which Groovy 6 loads only with groovy-callsite; the generated application, compiled with invokedynamic and without the module, could not load the @Integration transform or the JSON view compiler. Until the module left grails-common every application got it transitively. A real application never meets a classic-compiled Grails, since a published one is compiled with invokedynamic, so the generated build files stay as Forge writes them. Instead, in that lane, the Forge build names an init script in a system property of the test tasks that build generated applications, and both harnesses run every generated build with it. The script declares the module on every source set of the generated project, as any application that depends on a library compiled that way must. GeneratedBuild in the CLI module's test fixtures turns the property into the arguments, and GeneratedBuildSpec covers it.
This comment has been minimized.
This comment has been minimized.
| } | ||
| gradleCommand.append(' --no-daemon -S ').append(command) | ||
| gradleCommand.append(' --no-daemon -S ') | ||
| GeneratedBuild.arguments().each { String argument -> gradleCommand.append(argument).append(' ') } |
There was a problem hiding this comment.
[P2] Preserve the init-script path as a single process argument
When Forge runs with -PgrailsIndy=false, GeneratedBuild.arguments() contains the absolute checkout path to the init script. Joining it into this string loses its argument boundary: executeCommand() subsequently calls split(" ") before constructing ProcessBuilder. A checkout such as /work/Grails Sources/grails-core therefore passes /work/Grails as the init-script path and the remainder as another argument, so generated-app builds fail before executing their tasks. Please assemble and pass a List<String> through to ProcessBuilder, retaining the init-script path as one element; adding quotes to the string will not fix the existing split. A path-with-spaces regression case would cover this.
apache#16165 made invokedynamic the default for the framework's plugin modules and for applications, so grails-gsp, grails-sitemesh3 and grails-cache are no longer published with classic call sites.
Purpose
Enable Groovy invokedynamic by default on Grails 9.
Grails 7 disabled indy because Groovy 4 paid a 2-8x penalty (#15293). Grails 9 is on Groovy 6. Earlier A/B work on
perf/indy-vs-callsite-g6showed:That is still a large improvement over the old 2-8x hit. This PR flips the default so generated apps and published framework modules match Groovy 6's preferred dispatch. The
performancelabel is set so CI JMH can measure this default against9.0.x.What changed
grails { indy }is now unset by default, and the Grails Gradle plugin applies it toGroovyCompiletasks only when the application sets it. Gradle passes no indy option otherwise, so the Groovy compiler keeps its own default, which is invokedynamic on Groovy 6. Grails 8 keeps overriding it withfalse(Groovy - invoke dynamic performance problems #15293).grails { indy = false }plusimplementation 'org.apache.groovy:groovy-callsite', which the Grails BOM manages. Grails no longer carries the module:grails-common'sapidependency on it is removed, so an application that keeps the default never ships it. The Groovy compiler names the module when it is missing.true, and the build fails with the reason if it setsgrails { indy = false }: a classic call site defines a class at run time, which a native image cannot do. Each Groovy compile task of such a project also checks its ownindyoption as it starts, so a build script that sets it tofalseon the task after the plugin has configured it fails the same way instead of building a broken image.with()blocks, the functional test app'sHackControllerkeepssession[name], and the security taglib keeps its Map-coercedFilterChain. The earlier rewrites worked around Spock 2.4's Groovy 5 build on Groovy 6; with Spock 2.5-groovy-6.0 thewith()conditions dispatch correctly when compiled with indy, and themisctest configuration's specs andSecurityTagLibUnitSpecpass with the original code compiled with indy. All of those files are identical to 9.0.x again.-PgrailsIndy=falselane gets the module fromCompilePlugin, which declaresgroovy-callsiteon every source set of every module of the invoked build (not the included builds, whose Gradle plugins run on Gradle's own Groovy): a module compiled with invokedynamic may still compile or run against a classic-compiled one in that lane, such as a test module against a plugin module's test fixtures, or the GSON view compiler against a plugin's classes. The version is read fromdependencies.gradle's map, applied to the root project once in that lane, because theastsource set the Grails plugin gives every plugin project has no platform on its configurations. Thespring-security/ui/commonmodule now applies the compile convention plugin like every other Groovy-compiling module. The Forge CLI fixtures' own declaration is gone.-PgrailsIndy=falsepublish a classic-compiled framework tobuild/local-mavenfor the applications the specs generate. Those applications now declare the module as any application consuming a classic-compiled library must: the Forge build namesgrails-forge/gradle/classic-framework.init.gradlein a system property of the test tasks, and both harnesses run every generated build with it (GeneratedBuildin the CLI module's test fixtures). The generated build files stay as Forge writes them; a published Grails is compiled with invokedynamic, so a real application never needs this.testcontainers-spock(1.x and 2.x) is one; Spock 2.5, Geb 8 and Asset Pipeline 5.2.2 are not. The four modules that test with it declaretestRuntimeOnly 'org.apache.groovy:groovy-callsite'next to it, and the docs and skills describe the case.CompilePlugin, a963c8b), so this PR no longer changesCompilePlugin.whatsNew.adoc, the 9.0 upgrade guide and the AOT deployment chapter document the change, the opt-out and the native-image rule.grails-developerskill tells agents to remove the indy settings andgroovy-callsitedependency a Grails 7 or 8 build carried, and offers classic call sites as the alternative; thegradle-developerskill and AGENTS.md record thatgroovy-callsiteis never a framework dependency and how the-PgrailsIndy=falselanes get it.Not in this PR
The full app-bench harness from
perf/indy-vs-callsite-g6is not copied here. That branch is 3.7k lines and stale vs current9.0.x. CI JMH via theperformancelabel is the measurement path.Test plan
GrailsExtensionSpecunset default and opt-out;GrailsIndySpec(TestKit) unset,falseandtrueon every compile task, and the compiled bytecode's call sites for each (invokedynamic when unset ortrue, classic whenfalse);GrailsNativeImageDefaultsSpeckeeps an image's compile tasks indy, accepts an explicittrue, failsgrails { indy = false }at evaluation, and fails a compile task set to classic call sites after the plugin configured itperformanceJMH vs9.0.x