This is an automated email from the ASF dual-hosted git repository.
jdaugherty pushed a commit to branch feat/indy-default-groovy6
in repository https://gitbox.apache.org/repos/asf/grails-core.git
The following commit(s) were added to refs/heads/feat/indy-default-groovy6 by
this push:
new d71024dd8b Leave indy at the Groovy compiler's default unless the
application sets it
d71024dd8b is described below
commit d71024dd8b31c65d4bb1cc4465bedeeb90dc0059
Author: James Daugherty <[email protected]>
AuthorDate: Wed Oct 14 19:07:42 2026 +0100
Leave indy at the Groovy compiler's default unless the application sets 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.
---
grails-doc/src/en/guide/introduction/whatsNew.adoc | 13 +++--
.../src/en/guide/upgrading/upgrading90x.adoc | 17 +++++++
.../gradle/plugin/core/GrailsExtension.groovy | 12 +++--
.../gradle/plugin/core/GrailsGradlePlugin.groovy | 27 +++++-----
.../gradle/plugin/core/GrailsExtensionSpec.groovy | 4 +-
.../gradle/plugin/core/GrailsIndySpec.groovy | 58 ++++++++++++++++++++++
.../core/GrailsNativeImageDefaultsSpec.groovy | 8 +--
.../test-projects/indy-settings/build.gradle | 22 ++++++++
.../test-projects/indy-settings/gradle.properties | 1 +
.../indy-settings/grails-app/conf/application.yml | 0
.../test-projects/indy-settings/settings.gradle | 1 +
.../test-projects/native-defaults-off/build.gradle | 7 ++-
.../test-projects/native-defaults-on/build.gradle | 7 ++-
13 files changed, 142 insertions(+), 35 deletions(-)
diff --git a/grails-doc/src/en/guide/introduction/whatsNew.adoc
b/grails-doc/src/en/guide/introduction/whatsNew.adoc
index 5dda2610ff..22e8474aea 100644
--- a/grails-doc/src/en/guide/introduction/whatsNew.adoc
+++ b/grails-doc/src/en/guide/introduction/whatsNew.adoc
@@ -42,14 +42,13 @@ See xref:commandLine#gradleConfigurationCache[Using the
Gradle Configuration Cac
Grails Micronaut is maintained and released from the
https://github.com/apache/grails-micronaut[Apache Grails Micronaut repository]
and consumes published Grails Core artifacts.
-==== Groovy invokedynamic enabled by default
+==== Groovy's invokedynamic default applies again
-Grails 7 disabled Groovy invokedynamic for `GroovyCompile` tasks because of
performance regressions on Groovy 4
(https://github.com/apache/grails-core/issues/15293[#15293]).
-Grails 9 turns invokedynamic back on by default for generated apps (`grails {
indy }`) and published framework modules (`CompilePlugin`).
-You do not need to set `grails { indy = true }`.
-That matches Groovy 6's preferred dispatch. CI can still compile without indy
via `-PgrailsIndy=false`.
+Grails 7 and 8 compile every Groovy source set of an application without
invokedynamic, because Groovy 4 and 5 ran dynamic code markedly slower with it
(https://github.com/apache/grails-core/issues/15293[#15293]).
+Grails 9 runs on Groovy 6 and no longer overrides the compiler: unless the
build sets `grails { indy }`, each Groovy compile task keeps the Groovy
compiler's own default, which is invokedynamic.
+Grails' own published modules are compiled with invokedynamic as well.
-To keep classic callsite bytecode:
+To keep compiling classic call sites, set it in `build.gradle`:
[source,groovy]
.build.gradle
@@ -59,7 +58,7 @@ grails {
}
----
-Non-indy builds on Groovy 6 need `org.apache.groovy:groovy-callsite` on the
classpath. The Grails BOM already manages that coordinate.
+On Groovy 6, classic call sites need `org.apache.groovy:groovy-callsite` on
the classpath. A Grails application already receives it through its Grails
dependencies, at the version the Grails BOM manages.
==== Spring Boot 4.1 and Spring Framework 7
diff --git a/grails-doc/src/en/guide/upgrading/upgrading90x.adoc
b/grails-doc/src/en/guide/upgrading/upgrading90x.adoc
index c40de2e35c..44c669689d 100644
--- a/grails-doc/src/en/guide/upgrading/upgrading90x.adoc
+++ b/grails-doc/src/en/guide/upgrading/upgrading90x.adoc
@@ -46,3 +46,20 @@ The Groovy actor event bus delivers each event to its
subscribers in publication
Applications that use GPars directly, for example `GParsPool.withPool {
list.eachParallel { } }`, should move to the Groovy equivalents: the parallel
collection methods are available on every `Collection` without a pool, and
`groovy.concurrent.ParallelScope.withPool(n) { scope -> list.eachParallel { }
}` runs them on a pool of a chosen size. Once the deprecated modules are
removed, Grails will no longer bring GPars onto the classpath, so an
application that still needs it must declare `o [...]
NOTE: Groovy 6 marks the concurrency toolkit as incubating. The Grails modules
that build on it expose only the Grails `Promise` and `EventBus` contracts, so
changes to the Groovy API in later Groovy releases are absorbed by Grails
rather than by application code.
+
+==== 2. Groovy Code Is Compiled with invokedynamic
+
+Grails 8 compiles every Groovy source set of an application without
invokedynamic (`grails { indy = false }` was the default). Grails 9 leaves the
setting unset, so the Groovy compiler's own default applies, and on Groovy 6
that is invokedynamic. An application that set `grails { indy = true }` can
remove the line.
+
+An application that has to keep classic call sites, for example while it
measures the difference, sets the property explicitly:
+
+[source,groovy]
+.build.gradle
+----
+grails {
+ indy = false
+}
+----
+
+Classic call sites on Groovy 6 need `org.apache.groovy:groovy-callsite` on the
classpath, which a Grails application receives through its Grails dependencies.
A source set that does not see the application's dependencies, such as the test
fixtures of Gradle's `java-test-fixtures` plugin, needs that dependency
declared for it as well when `indy` is `false`.
+
diff --git
a/grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsExtension.groovy
b/grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsExtension.groovy
index 332f9435f5..eaf28bbeec 100644
---
a/grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsExtension.groovy
+++
b/grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsExtension.groovy
@@ -47,7 +47,7 @@ class GrailsExtension {
GrailsExtension(Project project) {
this.project = project
this.pluginDefiner = new PluginDefiner(project)
- this.indy = project.objects.property(Boolean).convention(true)
+ this.indy = project.objects.property(Boolean)
this.preserveParameterNames =
project.objects.property(Boolean).convention(true)
this.compileStatic =
project.objects.newInstance(GrailsCompileStaticOptions)
this.gorm = project.objects.newInstance(GrailsGormOptions)
@@ -242,10 +242,12 @@ class GrailsExtension {
boolean micronautAutoSetup = true
/**
- * Whether to enable Groovy's invokedynamic (indy) bytecode instruction
for dynamic Groovy method dispatch.
- * Enabled by default on Grails 9 / Groovy 6. Grails 7 disabled it for
performance on Groovy 4
- * (see GitHub issue #15293). Groovy uses JVM invokedynamic instead of
classic callsite caching.
- * To opt out in build.gradle: grails { indy = false }
+ * Whether Groovy compiles dynamic calls with the JVM's invokedynamic
instruction (indy) or with classic
+ * call sites. Unset by default: the Grails plugin then leaves every
Groovy compile task at the Groovy
+ * compiler's own default, which is invokedynamic. Set it to {@code false}
to compile classic call sites;
+ * on Groovy 6 those need {@code org.apache.groovy:groovy-callsite} on the
classpath, which a Grails
+ * application receives through its Grails dependencies. A value set here
is applied to every
+ * {@code GroovyCompile} task, replacing a value a build script set on the
task itself.
*/
final Property<Boolean> indy
diff --git
a/grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy
b/grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy
index 6e259555d5..2a44bfc95d 100644
---
a/grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy
+++
b/grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy
@@ -273,11 +273,14 @@ class GrailsGradlePlugin implements Plugin<Project> {
// Configure indy and log status after evaluation so user's grails { }
block has been applied
GrailsExtension grailsExtension =
project.extensions.findByType(GrailsExtension)
project.afterEvaluate {
- boolean indyEnabled = grailsExtension.indy.getOrElse(true)
+ Boolean indy = grailsExtension.indy.getOrNull()
Boolean preserveParameterNames =
grailsExtension.preserveParameterNames.getOrNull()
project.tasks.withType(GroovyCompile).configureEach {
GroovyCompile c ->
- c.groovyOptions.optimizationOptions.indy = indyEnabled
+ // unset leaves the task at the Groovy compiler's own default,
invokedynamic
+ if (indy != null) {
+ c.groovyOptions.optimizationOptions.indy = indy
+ }
if (preserveParameterNames != null) {
project.logger.info('Grails: Configuring Groovy
compilation to preserve parameter names: {}', preserveParameterNames)
@@ -285,9 +288,11 @@ class GrailsGradlePlugin implements Plugin<Project> {
}
}
- if (indyEnabled) {
- project.logger.info('Grails: Groovy invokedynamic (indy) is
enabled (Grails 9 default).')
- project.logger.info(' To disable invokedynamic: grails
{ indy = false } in build.gradle')
+ if (indy == null) {
+ project.logger.info("Grails: Groovy invokedynamic (indy) is
left at the Groovy compiler's default.")
+ project.logger.info(' To compile classic call sites:
grails { indy = false } in build.gradle')
+ } else if (indy) {
+ project.logger.info('Grails: Groovy invokedynamic (indy) is
enabled.')
} else {
project.logger.info('Grails: Groovy invokedynamic (indy) is
disabled.')
project.logger.info(' Non-indy Groovy 6 builds need
org.apache.groovy:groovy-callsite on the classpath.')
@@ -1118,19 +1123,15 @@ ${importStatements}
/**
* What a Grails application needs of a native image that an image cannot
work out for itself.
*
- * <p>Applications resolve calls through invokedynamic here, because the
classic call site
- * defines a class as it runs and an image has no way to define one. The
framework has to be
- * built the same way. This is a convention, so an application that has
said otherwise keeps
- * what it said.</p>
+ * <p>An image needs calls resolved through invokedynamic, because the
classic call site defines
+ * a class as it runs and an image has no way to define one. That is the
Groovy compiler's own
+ * default, which the plugin leaves in place unless the application sets
{@code grails { indy }},
+ * so an image needs nothing from here for it.</p>
*
* <p>Nothing here runs unless the application applies GraalVM's plugin,
which is what asks for
* an image in the first place. An application that never builds one is
untouched.</p>
*/
protected void configureNativeImage(Project project) {
- project.pluginManager.withPlugin('org.graalvm.buildtools.native') {
- GrailsExtension grailsExt =
project.extensions.getByType(GrailsExtension)
- grailsExt.indy.convention(true)
- }
configureNativeMetadataTrace(project)
}
diff --git
a/grails-gradle/plugins/src/test/groovy/org/grails/gradle/plugin/core/GrailsExtensionSpec.groovy
b/grails-gradle/plugins/src/test/groovy/org/grails/gradle/plugin/core/GrailsExtensionSpec.groovy
index 15dd242b6f..b10b289f2e 100644
---
a/grails-gradle/plugins/src/test/groovy/org/grails/gradle/plugin/core/GrailsExtensionSpec.groovy
+++
b/grails-gradle/plugins/src/test/groovy/org/grails/gradle/plugin/core/GrailsExtensionSpec.groovy
@@ -219,7 +219,7 @@ class GrailsExtensionSpec extends Specification {
extension.compileStatic.gsp.get()
}
- def "indy defaults to enabled"() {
+ def "indy is unset by default, which leaves the Groovy compiler's own
default in place"() {
given:
Project project = ProjectBuilder.builder().build()
@@ -227,7 +227,7 @@ class GrailsExtensionSpec extends Specification {
GrailsExtension extension = new GrailsExtension(project)
then:
- extension.indy.get()
+ !extension.indy.present
}
def "indy can be opted out"() {
diff --git
a/grails-gradle/plugins/src/test/groovy/org/grails/gradle/plugin/core/GrailsIndySpec.groovy
b/grails-gradle/plugins/src/test/groovy/org/grails/gradle/plugin/core/GrailsIndySpec.groovy
new file mode 100644
index 0000000000..23ef9faf11
--- /dev/null
+++
b/grails-gradle/plugins/src/test/groovy/org/grails/gradle/plugin/core/GrailsIndySpec.groovy
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.grails.gradle.plugin.core
+
+import org.gradle.testkit.runner.BuildResult
+
+/**
+ * Covers how {@code grails { indy }} reaches an application's Groovy compile
tasks: not at all when
+ * the application leaves it unset, so the Groovy compiler keeps its own
default, and on every task
+ * when the application sets it.
+ *
+ * @since 9.0
+ */
+class GrailsIndySpec extends GradleSpecification {
+
+ void 'an application that does not set indy compiles with the Groovy
compiler default'() {
+ given:
+ setupTestResourceProject('indy-settings')
+
+ when:
+ BuildResult result = executeTask('inspectIndy')
+
+ then: 'no compile task is given an indy option, so Groovy compiles
invokedynamic call sites'
+ result.output.contains('compileGroovy=unset')
+ result.output.contains('compileTestGroovy=unset')
+ }
+
+ void 'indy = #indy is applied to every Groovy compile task'() {
+ given:
+ setupTestResourceProject('indy-settings')
+
+ when:
+ BuildResult result = executeTask('inspectIndy',
["-PfixtureIndy=${indy}" as String])
+
+ then:
+ result.output.contains("compileGroovy=${indy}")
+ result.output.contains("compileTestGroovy=${indy}")
+
+ where:
+ indy << [false, true]
+ }
+}
diff --git
a/grails-gradle/plugins/src/test/groovy/org/grails/gradle/plugin/core/GrailsNativeImageDefaultsSpec.groovy
b/grails-gradle/plugins/src/test/groovy/org/grails/gradle/plugin/core/GrailsNativeImageDefaultsSpec.groovy
index 3c54876b96..cd973d2039 100644
---
a/grails-gradle/plugins/src/test/groovy/org/grails/gradle/plugin/core/GrailsNativeImageDefaultsSpec.groovy
+++
b/grails-gradle/plugins/src/test/groovy/org/grails/gradle/plugin/core/GrailsNativeImageDefaultsSpec.groovy
@@ -41,8 +41,8 @@ class GrailsNativeImageDefaultsSpec extends
GradleSpecification {
when:
BuildResult result = executeTask('inspectDefaults')
- then: 'invokedynamic stays off, as it is for every application that
did not ask for it'
- result.output.contains('INDY=false')
+ then: 'the compiler keeps its own default, invokedynamic, as it does
for every application that set no other'
+ result.output.contains('INDY_OPTION=unset')
and: 'and nothing an image would want has been added'
result.output.contains('HAS_NATIVE_EXTENSION=false')
@@ -66,8 +66,8 @@ class GrailsNativeImageDefaultsSpec extends
GradleSpecification {
when:
BuildResult result = executeTask('inspectDefaults')
- then: 'a classic call site defines a class as it runs, which an image
has no way to do'
- result.output.contains('INDY=true')
+ then: 'a classic call site defines a class as it runs, which an image
has no way to do, and nothing replaces the invokedynamic default'
+ result.output.contains('INDY_OPTION=unset')
}
void 'the pages are recorded after they are compiled, not before'() {
diff --git
a/grails-gradle/plugins/src/test/resources/test-projects/indy-settings/build.gradle
b/grails-gradle/plugins/src/test/resources/test-projects/indy-settings/build.gradle
new file mode 100644
index 0000000000..12863e4b94
--- /dev/null
+++
b/grails-gradle/plugins/src/test/resources/test-projects/indy-settings/build.gradle
@@ -0,0 +1,22 @@
+plugins {
+ id 'org.apache.grails.gradle.grails-app'
+}
+
+// -PfixtureIndy=<true|false> stands in for an application that sets grails {
indy }
+if (providers.gradleProperty('fixtureIndy').present) {
+ grails {
+ indy = providers.gradleProperty('fixtureIndy').get().toBoolean()
+ }
+}
+
+tasks.register('inspectIndy') {
+ def options = providers.provider {
+ project.tasks.withType(GroovyCompile).collect { GroovyCompile task ->
+ Map<String, Boolean> optimization =
task.groovyOptions.optimizationOptions
+ "${task.name}=${optimization.containsKey('indy') ?
optimization.indy : 'unset'}".toString()
+ }.sort()
+ }
+ doLast {
+ options.get().each { println it }
+ }
+}
diff --git
a/grails-gradle/plugins/src/test/resources/test-projects/indy-settings/gradle.properties
b/grails-gradle/plugins/src/test/resources/test-projects/indy-settings/gradle.properties
new file mode 100644
index 0000000000..35c332fb87
--- /dev/null
+++
b/grails-gradle/plugins/src/test/resources/test-projects/indy-settings/gradle.properties
@@ -0,0 +1 @@
+grailsVersion=__PROJECT_VERSION__
diff --git
a/grails-gradle/plugins/src/test/resources/test-projects/indy-settings/grails-app/conf/application.yml
b/grails-gradle/plugins/src/test/resources/test-projects/indy-settings/grails-app/conf/application.yml
new file mode 100644
index 0000000000..e69de29bb2
diff --git
a/grails-gradle/plugins/src/test/resources/test-projects/indy-settings/settings.gradle
b/grails-gradle/plugins/src/test/resources/test-projects/indy-settings/settings.gradle
new file mode 100644
index 0000000000..f5c7e718dd
--- /dev/null
+++
b/grails-gradle/plugins/src/test/resources/test-projects/indy-settings/settings.gradle
@@ -0,0 +1 @@
+rootProject.name = 'indy-settings'
diff --git
a/grails-gradle/plugins/src/test/resources/test-projects/native-defaults-off/build.gradle
b/grails-gradle/plugins/src/test/resources/test-projects/native-defaults-off/build.gradle
index 8507967e32..1a754c0c85 100644
---
a/grails-gradle/plugins/src/test/resources/test-projects/native-defaults-off/build.gradle
+++
b/grails-gradle/plugins/src/test/resources/test-projects/native-defaults-off/build.gradle
@@ -5,10 +5,13 @@ plugins {
// An application that builds neither an image nor a cache applies neither
plugin, and so should
// find nothing has been decided on its behalf.
tasks.register('inspectDefaults') {
- def indy = providers.provider {
project.extensions.getByName('grails').indy.get() }
+ def indyOption = providers.provider {
+ Map<String, Boolean> options = project.tasks.named('compileGroovy',
GroovyCompile).get().groovyOptions.optimizationOptions
+ options.containsKey('indy') ? String.valueOf(options.indy) : 'unset'
+ }
def hasNativeExtension = providers.provider {
project.extensions.findByName('graalvmNative') != null }
doLast {
- println "INDY=${indy.get()}"
+ println "INDY_OPTION=${indyOption.get()}"
println "HAS_NATIVE_EXTENSION=${hasNativeExtension.get()}"
}
}
diff --git
a/grails-gradle/plugins/src/test/resources/test-projects/native-defaults-on/build.gradle
b/grails-gradle/plugins/src/test/resources/test-projects/native-defaults-on/build.gradle
index f329ddb23d..6f0dc5b6ee 100644
---
a/grails-gradle/plugins/src/test/resources/test-projects/native-defaults-on/build.gradle
+++
b/grails-gradle/plugins/src/test/resources/test-projects/native-defaults-on/build.gradle
@@ -4,8 +4,11 @@ plugins {
}
tasks.register('inspectDefaults') {
- def indy = providers.provider {
project.extensions.getByName('grails').indy.get() }
+ def indyOption = providers.provider {
+ Map<String, Boolean> options = project.tasks.named('compileGroovy',
GroovyCompile).get().groovyOptions.optimizationOptions
+ options.containsKey('indy') ? String.valueOf(options.indy) : 'unset'
+ }
doLast {
- println "INDY=${indy.get()}"
+ println "INDY_OPTION=${indyOption.get()}"
}
}