Skip to content

Commit 91be40c

Browse files
committed
update to use GrailsExtension parameter name flag
1 parent a95f303 commit 91be40c

8 files changed

Lines changed: 33 additions & 61 deletions

File tree

grails-doc/src/en/guide/introduction/whatsNew.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,7 @@ Notable new features are included below.
3232
Grails 8 continues the move toward method-based TagLib handlers while preserving compatibility with existing closure-based tags.
3333
Method-defined tags now bind named attributes more predictably, exclude inherited framework and `Object` methods from tag dispatch, and preserve real namespace property getters.
3434

35+
The Grails Gradle extension now defaults `preserveParameterNames` to `true`, so application Groovy compilation preserves method parameter names for features such as typed method TagLib arguments.
36+
3537
Tag library unit tests also clean up and rebuild TagLib metadata automatically between features.
3638
Tests that use `TagLibUnitTest` no longer need to manage `purgeTagLibMetaClass`, and specs that mock additional tag libraries continue to work across feature methods.

grails-doc/src/en/guide/upgrading/upgrading80x.adoc

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,35 @@ class MyTagLibSpec extends Specification implements TagLibUnitTest<MyTagLib> {
677677
}
678678
----
679679

680-
==== 21. Known Plugin Incompatibilities
680+
==== 21. Grails Gradle Extension Preserves Parameter Names By Default
681+
682+
In Grails 8, the Grails Gradle extension defaults `preserveParameterNames` to `true`.
683+
This configures Groovy compilation to retain method and constructor parameter names in generated class files.
684+
685+
This behavior supports framework features that bind by parameter name, including method-based TagLib handlers annotated with `@grails.gsp.Tag`:
686+
687+
[source,groovy]
688+
----
689+
import grails.gsp.Tag
690+
691+
class DemoTagLib {
692+
@Tag
693+
def greeting(String name) {
694+
out << "Hello, ${name}!"
695+
}
696+
}
697+
----
698+
699+
If you need the previous Groovy compiler behavior, disable it in `build.gradle`:
700+
701+
[source,groovy]
702+
----
703+
grails {
704+
preserveParameterNames = false
705+
}
706+
----
707+
708+
==== 22. Known Plugin Incompatibilities
681709

682710
Some third-party plugins have not yet been updated for Spring Boot 4 / Spring Framework 7 compatibility.
683711
The following are known blockers at this time:
@@ -690,7 +718,7 @@ Applications using `grails-sitemesh3` should remain on the `grails-layout` plugi
690718

691719
Check the https://github.com/apache/grails-core/issues[Grails issue tracker] for the latest status of plugin compatibility.
692720

693-
===== 22. Custom JSON View Converters
721+
===== 23. Custom JSON View Converters
694722

695723
JSON views now use Groovy's `groovy.json.JsonGenerator` implementation instead of the previous Grails-specific
696724
JSON generator infrastructure.

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ import org.gradle.api.tasks.SourceSetOutput
5858
import org.gradle.api.tasks.TaskContainer
5959
import org.gradle.api.tasks.TaskProvider
6060
import org.gradle.api.tasks.compile.GroovyCompile
61-
import org.gradle.api.tasks.compile.JavaCompile
6261
import org.gradle.api.tasks.testing.Test
6362
import org.gradle.jvm.toolchain.JavaToolchainService
6463
import org.gradle.language.jvm.tasks.ProcessResources
@@ -190,8 +189,6 @@ class GrailsGradlePlugin implements Plugin<Project> {
190189

191190
private void configureGroovyCompiler(Project project) {
192191
project.tasks.withType(GroovyCompile).configureEach { GroovyCompile c ->
193-
c.groovyOptions.parameters = true
194-
195192
// Use a task-specific config file to avoid overlapping outputs when multiple
196193
// GroovyCompile tasks exist in the same project (e.g. compileGroovy, compileTestGroovy).
197194
Provider<RegularFile> groovyCompilerConfigFile = project.layout.buildDirectory.file("grailsGroovyCompilerConfig-${c.name}.groovy")
@@ -233,12 +230,6 @@ class GrailsGradlePlugin implements Plugin<Project> {
233230
}
234231
}
235232

236-
project.tasks.withType(JavaCompile).configureEach { JavaCompile c ->
237-
if (!c.options.compilerArgs.contains('-parameters')) {
238-
c.options.compilerArgs.add('-parameters')
239-
}
240-
}
241-
242233
// Configure indy and log status after evaluation so user's grails { } block has been applied
243234
GrailsExtension grailsExtension = project.extensions.findByType(GrailsExtension)
244235
project.afterEvaluate {
@@ -249,6 +240,7 @@ class GrailsGradlePlugin implements Plugin<Project> {
249240
c.groovyOptions.optimizationOptions.indy = indyEnabled
250241

251242
if (preserveParameterNames != null) {
243+
logger.info("Grails: Configuring Groovy compilation to preserve parameter names: {}", preserveParameterNames)
252244
c.groovyOptions.parameters = preserveParameterNames
253245
}
254246
}

grails-gradle/plugins/src/test/groovy/org/grails/gradle/plugin/core/GrailsGradlePluginParameterMetadataSpec.groovy

Lines changed: 0 additions & 34 deletions
This file was deleted.

grails-gradle/plugins/src/test/resources/test-projects/parameter-metadata/build.gradle

Lines changed: 0 additions & 12 deletions
This file was deleted.

grails-gradle/plugins/src/test/resources/test-projects/parameter-metadata/gradle.properties

Lines changed: 0 additions & 1 deletion
This file was deleted.

grails-gradle/plugins/src/test/resources/test-projects/parameter-metadata/grails-app/conf/application.yml

Lines changed: 0 additions & 2 deletions
This file was deleted.

grails-gradle/plugins/src/test/resources/test-projects/parameter-metadata/settings.gradle

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)