-
-
Notifications
You must be signed in to change notification settings - Fork 970
Preserving Parameter Names #15382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 8.0.x
Are you sure you want to change the base?
Preserving Parameter Names #15382
Changes from 10 commits
38e1ed7
127f01e
13675ab
7661d1c
1a83ae0
88586a0
8ec535d
aa0afee
f231d92
90b8a5a
fc9a55a
f888201
fa61946
de806d8
f531f61
7032937
a4f2739
7d9e779
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -106,6 +107,15 @@ class GrailsExtension { | |
| this.indy.set(enabled) | ||
| } | ||
|
|
||
| /** | ||
| * Keep class file parameter names so autowire by name can be supported without additional annotations such as '@qualifier'. | ||
| */ | ||
| final Property<Boolean> preserveParameterNames | ||
|
|
||
| void setPreserveParameterNames(boolean enabled) { | ||
|
||
| this.preserveParameterNames.set(enabled) | ||
| } | ||
|
|
||
| DependencyHandler getPlugins() { | ||
| if (pluginDefiner == null) { | ||
| pluginDefiner = new PluginDefiner(project) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -228,10 +228,17 @@ class GrailsGradlePlugin implements Plugin<Project> { | |
|
|
||
| // Configure indy and log status after evaluation so user's grails { } block has been applied | ||
| project.afterEvaluate { | ||
| boolean indyEnabled = grailsExtension?.indy?.getOrElse(false) ?: false | ||
| boolean indyEnabled = grailsExtension.indy?.getOrElse(false) ?: false | ||
| boolean preserveParameterNames = grailsExtension.preserveParameterNames?.getOrElse(true) | ||
|
|
||
| project.tasks.withType(GroovyCompile).configureEach { GroovyCompile c -> | ||
| c.groovyOptions.optimizationOptions.indy = indyEnabled | ||
|
|
||
| if (preserveParameterNames) { | ||
|
||
| 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') | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| 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 "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}" | ||
jdaugherty marked this conversation as resolved.
Show resolved
Hide 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' |
Uh oh!
There was an error while loading. Please reload this page.