Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
38e1ed7
Preserving Parameter Names
rahulshishodia Feb 11, 2026
127f01e
updated skeleton build.gradle
rahulshishodia Feb 11, 2026
13675ab
Merge branch '8.0.x' into preserve-param-names
rahulshishodia Feb 28, 2026
7661d1c
removed hardcoded UTF_8 encoding as not all files are UTF-8 encoded a…
rahulshishodia Feb 28, 2026
1a83ae0
Added preserve parameter in grails-gradle-plugin
rahulshishodia Feb 28, 2026
88586a0
reverted previous changes in build.gradle
rahulshishodia Feb 28, 2026
8ec535d
improved logging
rahulshishodia Mar 1, 2026
aa0afee
addressed review comments
rahulshishodia Mar 1, 2026
f231d92
addressed review comments #2
rahulshishodia Mar 2, 2026
90b8a5a
Merge branch '8.0.x' into preserve-param-names
rahulshishodia Mar 2, 2026
fc9a55a
Fix typo in Javadoc comment for preserveParameterNames
rahulshishodia Mar 12, 2026
f888201
added tests for explicit null
rahulshishodia Mar 12, 2026
fa61946
removed setter and exention initialization using ObjectFactory
rahulshishodia Mar 12, 2026
de806d8
Merge branch '8.0.x' into preserve-param-names
rahulshishodia Mar 26, 2026
f531f61
Merge branch '8.0.x' into preserve-param-names
jamesfredley Mar 30, 2026
7032937
Merge branch '8.0.x' into preserve-param-names
rahulshishodia Apr 4, 2026
a4f2739
Merge branch '8.0.x' into preserve-param-names
rahulshishodia Apr 8, 2026
7d9e779
Handled 3 states of preserveParameterNames
rahulshishodia Apr 7, 2026
95321a0
Merge branch '8.0.x' into preserve-param-names
rahulshishodia Apr 12, 2026
91ee3c2
Merge branch '8.0.x' into preserve-param-names
rahulshishodia Apr 24, 2026
1c3a1e4
Merge branch '8.0.x' into preserve-param-names
rahulshishodia Apr 24, 2026
7a1a0f0
Merge branch '8.0.x' into preserve-param-names
rahulshishodia Apr 25, 2026
a565e5c
Add license header to GrailsGradlePreserveParametersSpec
rahulshishodia Apr 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class GrailsExtension {
this.project = project
this.pluginDefiner = new PluginDefiner(project)
this.indy = project.objects.property(Boolean).convention(false)
this.preserveParameterNames = project.objects.property(Boolean).convention(true)
}

/**
Expand Down Expand Up @@ -106,6 +107,11 @@ class GrailsExtension {
this.indy.set(enabled)
}

/**
* Keep class file parameter names so autowire by name can be supported without additional annotations such as '@Qualifier'.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion (and keep line length under 120 for readability):
Keep method and constructor parameter names in class files, allowing frameworks such as Spring to use parameter names for dependency resolution, including autowiring by name without requiring annotations such as @Qualifier.

*/
Property<Boolean> preserveParameterNames
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be final.


DependencyHandler getPlugins() {
if (pluginDefiner == null) {
pluginDefiner = new PluginDefiner(project)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,17 @@ 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(false) ?: false
boolean indyEnabled = grailsExtension.indy?.getOrElse(false) ?: false
Boolean preserveParameterNames = grailsExtension.preserveParameterNames?.getOrNull()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • No need for null guard on grailsExtension.preserveParameterNames, it can never be null as it is constructed in the GrailsExtension constructor. (Same for grailsExtension.indy on the previous line).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it can be null if someone sets a provider- which says do not configure. this needs to stay

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdaugherty I tested, and it will still not be null with a provider { null }.


project.tasks.withType(GroovyCompile).configureEach { GroovyCompile c ->
c.groovyOptions.optimizationOptions.indy = indyEnabled

if (preserveParameterNames != null) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can never be null as its convention is true. If explicitly set to null in the extension configuration, it will still resolve to true as that is its convention setting.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it can, a user can set a provider that returns null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thank you! Can we create a test showing this in action?

c.groovyOptions.parameters = preserveParameterNames
}
}

if (!indyEnabled) {
project.logger.info('Grails: Groovy invokedynamic (indy) is disabled to improve performance (see issue #15293).')
project.logger.info(' To enable invokedynamic: grails { indy = true } in build.gradle')
Expand Down Expand Up @@ -520,7 +527,7 @@ ${importStatements}

protected GrailsExtension registerGrailsExtension(Project project) {
if (project.extensions.findByName('grails') == null) {
project.extensions.add('grails', new GrailsExtension(project))
project.extensions.create('grails', GrailsExtension, project)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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

class GrailsGradlePreserveParametersSpec extends GradleSpecification {

def "Grails extension is created with default preserveParameterNames = true"() {
given:
setupTestResourceProject('preserve-params-default')

when:
def result = executeTask('inspectPreserveParam')

then:
result.output.contains("HAS_PRESERVE_PARAM_ENABLED=true")
}

def "preserveParameterNames can be configured to false via grails block"() {
given:
setupTestResourceProject('preserve-params-disabled')

when:
def result = executeTask('inspectPreserveParam')

then:
result.output.contains("HAS_PRESERVE_PARAM_ENABLED=false")
}

def "preserveParameterNames is set to true when configured as explicit null"() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we be more descriptive as to why null => true? (fallback to the convention)

given:
setupTestResourceProject('preserve-params-null')

when:
def result = executeTask('inspectPreserveParam')

then:
result.output.contains("HAS_PRESERVE_PARAM_ENABLED=true")
}

def "GroovyCompile tasks get parameters = true when preserveParameterNames is enabled"() {
given:
setupTestResourceProject('preserve-params-enabled')

when:
def result = executeTask('inspectPreserveParam')

then:
result.output.contains("HAS_PRESERVE_PARAM_ENABLED=true")
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
plugins {
id 'org.apache.grails.gradle.grails-app'
}

tasks.register('inspectPreserveParam') {
doLast {
def compileTasks = tasks.withType(GroovyCompile)
def paramsEnabled = compileTasks.every { it.groovyOptions.parameters }
println "HAS_PRESERVE_PARAM_ENABLED=${paramsEnabled}"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
grailsVersion=__PROJECT_VERSION__
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'test-preserve-params-default'
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
plugins {
id 'org.apache.grails.gradle.grails-app'
}

grails {
preserveParameterNames = false
}

tasks.register('inspectPreserveParam') {
doLast {
def compileTasks = tasks.withType(GroovyCompile)
def paramsEnabled = compileTasks.every { it.groovyOptions.parameters }
println "HAS_PRESERVE_PARAM_ENABLED=${paramsEnabled}"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
grailsVersion=__PROJECT_VERSION__
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'test-preserve-params-disabled'
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
plugins {
id 'org.apache.grails.gradle.grails-app'
}

grails {
preserveParameterNames = true
}

tasks.register('inspectPreserveParam') {
doLast {
def compileTasks = tasks.withType(GroovyCompile)
def paramsEnabled = compileTasks.every { it.groovyOptions.parameters }
println "HAS_PRESERVE_PARAM_ENABLED=${paramsEnabled}"
Comment thread
jdaugherty marked this conversation as resolved.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
grailsVersion=__PROJECT_VERSION__
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'test-preserve-params-enabled'
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
plugins {
id 'org.apache.grails.gradle.grails-app'
}

grails {
preserveParameterNames = null
}

tasks.register('inspectPreserveParam') {
doLast {
def compileTasks = tasks.withType(GroovyCompile)
def paramsEnabled = compileTasks.every { it.groovyOptions.parameters }
println "HAS_PRESERVE_PARAM_ENABLED=${paramsEnabled}"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
grailsVersion=__PROJECT_VERSION__
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'test-preserve-params-null'
Loading