Skip to content

Preserving Parameter Names#15382

Open
rahulshishodia wants to merge 23 commits intoapache:8.0.xfrom
rahulshishodia:preserve-param-names
Open

Preserving Parameter Names#15382
rahulshishodia wants to merge 23 commits intoapache:8.0.xfrom
rahulshishodia:preserve-param-names

Conversation

@rahulshishodia
Copy link
Copy Markdown
Contributor

@rahulshishodia rahulshishodia commented Feb 11, 2026

Reference: org.apache.grails.buildsrc.CompilePlugin#configureCompiler
Issue: #13028

Copy link
Copy Markdown
Contributor

@jdaugherty jdaugherty left a comment

Choose a reason for hiding this comment

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

We maintain 2 app generation tools currently - both grails-profile based and grails-forge based. Can you please update the associated profile skeleton too?

@rahulshishodia
Copy link
Copy Markdown
Contributor Author

@jdaugherty - Thankyou for pointing this out! (TIL). I have added the same in grails-profiles/base/skeleton/build.gradle

@rahulshishodia
Copy link
Copy Markdown
Contributor Author

@jamesfredley Conflicts are now resolved, could you please run the pipeline again. Thanks!

@matrei
Copy link
Copy Markdown
Contributor

matrei commented Feb 28, 2026

If this is required I think we should default to it in GrailsGradlePlugin and provide an option on the extension to turn it off. Let's try to keep the build.gradle file clean.

@jdaugherty
Copy link
Copy Markdown
Contributor

The compile plugin is for our project while the GrailsGradlePlugin is for all grails projects.
Take a look under grails-gradle/plugins

@rahulshishodia
Copy link
Copy Markdown
Contributor Author

@jdaugherty I have used the compiler plugin as reference, changes are made in grails-gradle-plugins.

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

@rahulshishodia
Copy link
Copy Markdown
Contributor Author

@jdaugherty can you please take a look again

@jdaugherty
Copy link
Copy Markdown
Contributor

Assuming the tests pass, I'm good to merge this. @matrei Are you ok to merge this as well? I intend to update the grails docs separately from this PR.

@rahulshishodia
Copy link
Copy Markdown
Contributor Author

@jdaugherty I have added missing licence header, can you please re-trigger the workflow. Thanks!

@testlens-app
Copy link
Copy Markdown

testlens-app Bot commented Apr 26, 2026

✅ All tests passed ✅

🏷️ Commit: a565e5c
▶️ Tests: 15204 executed
⚪️ Checks: 34/34 completed


Learn more about TestLens at testlens.app.

/**
* Keep class file parameter names so autowire by name can be supported without additional 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.

}

/**
* 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.

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?

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants