Skip to content

Commit c9544f6

Browse files
committed
feat(grails-gradle): move indy configuration from generated apps to Gradle plugin
Move the Groovy invokedynamic (indy) configuration from generated build.gradle files to the Grails Gradle Plugin, centralizing the setting and providing user feedback. Changes: - Add 'indy' property to GrailsExtension (default: false) - Configure GroovyCompile tasks in GrailsGradlePlugin to use the extension's indy setting - Display lifecycle message explaining indy is disabled for performance and how to enable it - Remove hardcoded indy=false from grails-forge template - Remove hardcoded indy=false from grails-profiles base skeleton The message appears once per project during configuration: Grails: Groovy invokedynamic (indy) is disabled to improve performance (see issue #15293). To enable invokedynamic: grails { indy = true } in build.gradle Closes #15321
1 parent 69e47e3 commit c9544f6

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

grails-forge/grails-forge-core/src/main/java/org/grails/forge/feature/build/gradle/templates/buildGradle.rocker.raw

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,3 @@ assets {
142142

143143
}
144144

145-
// https://github.com/apache/grails-core/issues/15321
146-
tasks.withType(GroovyCompile).configureEach {
147-
groovyOptions.optimizationOptions.indy = false
148-
}

grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsExtension.groovy

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import groovy.transform.CompileStatic
2323
import org.apache.tools.ant.taskdefs.condition.Os
2424
import org.gradle.api.Project
2525
import org.gradle.api.artifacts.dsl.DependencyHandler
26+
import org.gradle.api.provider.Property
2627
import org.gradle.util.internal.ConfigureUtil
2728

2829
import grails.util.Environment
@@ -42,6 +43,7 @@ class GrailsExtension {
4243
GrailsExtension(Project project) {
4344
this.project = project
4445
this.pluginDefiner = new PluginDefiner(project)
46+
this.indy = project.objects.property(Boolean).convention(false)
4547
}
4648

4749
/**
@@ -76,6 +78,14 @@ class GrailsExtension {
7678
*/
7779
boolean micronautAutoSetup = true
7880

81+
/**
82+
* Whether to enable Groovy's invokedynamic (indy) bytecode instruction for dynamic Groovy method dispatch.
83+
* Disabled by default to improve performance (see GitHub issue #15293).
84+
* When enabled, Groovy uses JVM invokedynamic instead of traditional callsite caching.
85+
* To enable invokedynamic in build.gradle: grails { indy = true }
86+
*/
87+
final Property<Boolean> indy
88+
7989
DependencyHandler getPlugins() {
8090
if (pluginDefiner == null) {
8191
pluginDefiner = new PluginDefiner(project)

grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,14 @@ class GrailsGradlePlugin extends GroovyPlugin {
184184
private void configureGroovyCompiler(Project project) {
185185
Provider<RegularFile> groovyCompilerConfigFile = project.layout.buildDirectory.file('grailsGroovyCompilerConfig.groovy')
186186

187+
GrailsExtension grailsExtension = project.extensions.findByType(GrailsExtension)
188+
187189
project.tasks.withType(GroovyCompile).configureEach { GroovyCompile c ->
188190
c.outputs.file(groovyCompilerConfigFile)
189191

192+
// Configure indy option from GrailsExtension
193+
c.groovyOptions.optimizationOptions.indy = grailsExtension?.indy?.getOrElse(false) ?: false
194+
190195
Closure<String> userScriptGenerator = getGroovyCompilerScript(c, project)
191196
c.doFirst {
192197
// This isn't ideal - we're performing configuration at execution time, but the alternative would be having
@@ -216,6 +221,14 @@ class GrailsGradlePlugin extends GroovyPlugin {
216221
c.groovyOptions.configurationScript = combinedFile
217222
}
218223
}
224+
225+
// Log indy status once per project after evaluation
226+
project.afterEvaluate {
227+
if (!grailsExtension?.indy?.getOrElse(false)) {
228+
project.logger.lifecycle('Grails: Groovy invokedynamic (indy) is disabled to improve performance (see issue #15293).')
229+
project.logger.lifecycle(' To enable invokedynamic: grails { indy = true } in build.gradle')
230+
}
231+
}
219232
}
220233

221234
protected Closure<String> getGroovyCompilerScript(GroovyCompile compile, Project project) {

grails-profiles/base/skeleton/build.gradle

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,3 @@ tasks.withType(Test).configureEach {
2727
useJUnitPlatform()
2828
}
2929

30-
// https://github.com/apache/grails-core/issues/15321
31-
tasks.withType(GroovyCompile).configureEach {
32-
groovyOptions.optimizationOptions.indy = false
33-
}

0 commit comments

Comments
 (0)