You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@grails.apache.org by "jamesfredley (via GitHub)" <gi...@apache.org> on 2026/08/06 19:23:20 UTC
[PR] Configure generated applications for component scanning [grails-core]
jamesfredley opened a new pull request, #16111:
URL: https://github.com/apache/grails-core/pull/16111
## Summary
- add explicit base-package Spring component scanning to Forge-generated applications
- keep base and plugin profile Application skeletons aligned with Forge output
- verify all application types and standard Spring component injection without `resources.groovy`
- document the generated scanning default separately from Grails artefact scanning
## Verification
- `:grails-forge-core:check :test-core:check`
- `:grails-profiles-base:check :grails-profiles-plugin:check`
- `:grails-doc:publishGuide -x aggregateGroovydoc`
- `GrailsApplicationSpec`: 18 tests, 0 failures
- `CreateAppSpec` generated-source matrix: 4 tests, 0 failures
- mandatory Oracle and Codex review gate: GREEN
Closes #14914
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Configure generated applications for component scanning [grails-core]
Posted by "jamesfredley (via GitHub)" <gi...@apache.org>.
jamesfredley commented on PR #16111:
URL: https://github.com/apache/grails-core/pull/16111#issuecomment-5302947531
Moving back to draft since there is not agreement. It seemed that https://github.com/apache/grails-core/issues/14914 was cleared, but that is not the case.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Configure generated applications for component scanning [grails-core]
Posted by "matrei (via GitHub)" <gi...@apache.org>.
matrei commented on PR #16111:
URL: https://github.com/apache/grails-core/pull/16111#issuecomment-5292974441
- I would like to keep the starter templates as lean as possible.
- Is scanning needed by any Forge feature?
- Even though I'm sure people use it, this is not the typical documented Grails way of defining beans in an application, and it's easy enough to add if you want it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Configure generated applications for component scanning [grails-core]
Posted by "codeconsole (via GitHub)" <gi...@apache.org>.
codeconsole commented on PR #16111:
URL: https://github.com/apache/grails-core/pull/16111#issuecomment-5916055129
@jdaugherty component scanning introduces latency. That is why it requires the annotation. This is best a feature. We shouldn't influence new users to use things that aren't needed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Configure generated applications for component scanning [grails-core]
Posted by "codeconsole (via GitHub)" <gi...@apache.org>.
codeconsole commented on PR #16111:
URL: https://github.com/apache/grails-core/pull/16111#issuecomment-5296102124
I agree with @matrei I would like the starter app as lean as possible, but I also think it would be useful to expose all the possible settings as a feature. The base app should focus on doing as much as possible purely by convention. I am a huge proponent of convention over configuration.
@jamesfredley I think a good feature that you might like is like an opt-in "kitchen sink" feature that adds this and every possible default to `application.yml`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Configure generated applications for component scanning [grails-core]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #16111:
URL: https://github.com/apache/grails-core/pull/16111#discussion_r3731547471
##########
grails-forge/grails-forge-core/src/test/groovy/org/grails/forge/feature/lang/GrailsApplicationSpec.groovy:
##########
@@ -58,11 +59,26 @@ class GrailsApplicationSpec extends BeanContextSpec implements CommandOutputFixt
output.containsKey("grails-app/init/example/grails/Application.${Language.GROOVY.extension}".toString())
def applicationGroovyFile = output.get("grails-app/init/example/grails/Application.${Language.GROOVY.extension}".toString())
applicationGroovyFile.contains("@PluginSource")
+ applicationGroovyFile.contains("@ComponentScan(value = 'example.grails')")
where:
applicationType << [ApplicationType.PLUGIN, ApplicationType.WEB_PLUGIN]
}
+ void 'profile Application skeletons configure base-package component scanning'() {
+ given:
+ File profiles = new File('../../grails-profiles').canonicalFile
Review Comment:
Using a hard-coded relative path makes this test sensitive to the JVM working directory (e.g., different CI runners / IDEs). Prefer resolving the repository root via a known project/system property (or a classpath/resource-based approach) and then resolving `grails-profiles` from that stable base.
##########
grails-forge/grails-forge-core/src/test/groovy/org/grails/forge/feature/lang/GrailsApplicationSpec.groovy:
##########
@@ -58,11 +59,26 @@ class GrailsApplicationSpec extends BeanContextSpec implements CommandOutputFixt
output.containsKey("grails-app/init/example/grails/Application.${Language.GROOVY.extension}".toString())
def applicationGroovyFile = output.get("grails-app/init/example/grails/Application.${Language.GROOVY.extension}".toString())
applicationGroovyFile.contains("@PluginSource")
+ applicationGroovyFile.contains("@ComponentScan(value = 'example.grails')")
where:
applicationType << [ApplicationType.PLUGIN, ApplicationType.WEB_PLUGIN]
}
+ void 'profile Application skeletons configure base-package component scanning'() {
+ given:
+ File profiles = new File('../../grails-profiles').canonicalFile
+
+ expect:
+ ['base', 'plugin'].every { String profile ->
+ File application = new File(profiles, "${profile}/skeleton/grails-app/init/@grails.codegen.defaultPackage.path@/Application.groovy")
+ assert application.file, "missing profile Application skeleton ${application}"
+ assert application.text.contains('import org.springframework.context.annotation.ComponentScan')
Review Comment:
`application` is a `java.io.File`, and `application.file` is not a valid property/method on `File` (this will throw at runtime). Use an existence check such as `application.exists()` / `application.isFile()` instead so the assertion reliably validates the skeleton file is present.
##########
grails-forge/test-core/src/test/groovy/org/grails/forge/create/CreateAppSpec.groovy:
##########
@@ -60,72 +61,158 @@ class CreateAppSpec extends CommandSpec {
new File(dir, "grails-app/i18n").exists()
}
- void "test create-app creates a correct Application.groovy"() {
+ @Unroll
+ void "test create-app #applicationType creates a correct Application.groovy"() {
given:
- generateProject(OperatingSystem.MACOS_ARCH64, [], ApplicationType.DEFAULT_OPTION)
+ generateProject(OperatingSystem.MACOS_ARCH64, [], applicationType)
def applicationClassSourceFile = new File(dir, 'grails-app/init/example/grails/Application.groovy')
expect:
applicationClassSourceFile.exists()
- applicationClassSourceFile.text == '''\
+ applicationClassSourceFile.text == applicationSource.stripIndent(8)
+
+ where:
+ applicationType | applicationSource
+ ApplicationType.WEB | '''\
package example.grails
import groovy.transform.CompileStatic
+ import org.springframework.context.annotation.ComponentScan
+
import grails.boot.GrailsApp
import grails.boot.config.GrailsAutoConfiguration
@CompileStatic
+ @ComponentScan(value = 'example.grails')
class Application extends GrailsAutoConfiguration {
static void main(String[] args) {
GrailsApp.run(Application, args)
}
}
- '''.stripIndent(8)
- }
+ '''
+ ApplicationType.REST_API | '''\
+ package example.grails
- void "test create-app with micronaut feature"() {
- given:
- // Micronaut features require JDK 25+ because micronaut-core's ScopedValues
- // references java.lang.ScopedValue.CallableOp (JEP 506, finalized in JDK 25).
- generateProject(OperatingSystem.MACOS_ARCH64, ['grails-micronaut'], ApplicationType.WEB,
- DevelopmentReloading.DEFAULT_OPTION, JdkVersion.JDK_25)
+ import groovy.transform.CompileStatic
- def gradleProperties = new File(dir, 'gradle.properties')
- def gradleBuildFile = new File(dir, 'build.gradle')
+ import org.springframework.context.annotation.ComponentScan
- expect:
- gradleProperties.exists()
- gradleProperties.text.contains('micronautPlatformVersion=4.10.16')
- gradleBuildFile.exists()
- gradleBuildFile.text.contains('implementation "org.apache.grails:grails-micronaut"')
- }
+ import grails.boot.GrailsApp
+ import grails.boot.config.GrailsAutoConfiguration
- void "test create-app web-plugin creates a correct Application.groovy"() {
- given:
- generateProject(OperatingSystem.MACOS_ARCH64, [], ApplicationType.WEB_PLUGIN)
+ @CompileStatic
+ @ComponentScan(value = 'example.grails')
+ class Application extends GrailsAutoConfiguration {
+ static void main(String[] args) {
+ GrailsApp.run(Application, args)
+ }
+ }
+ '''
+ ApplicationType.PLUGIN | '''\
+ package example.grails
- def applicationClassSourceFile = new File(dir, 'grails-app/init/example/grails/Application.groovy')
+ import groovy.transform.CompileStatic
- expect:
- applicationClassSourceFile.exists()
- applicationClassSourceFile.text == '''\
+ import org.springframework.context.annotation.ComponentScan
+
+ import grails.boot.GrailsApp
+ import grails.boot.config.GrailsAutoConfiguration
+ import grails.plugins.metadata.PluginSource
+
+ @PluginSource
+ @CompileStatic
+ @ComponentScan(value = 'example.grails')
+ class Application extends GrailsAutoConfiguration {
+ static void main(String[] args) {
+ GrailsApp.run(Application, args)
+ }
+ }
+ '''
+ ApplicationType.WEB_PLUGIN | '''\
package example.grails
import groovy.transform.CompileStatic
+ import org.springframework.context.annotation.ComponentScan
+
import grails.boot.GrailsApp
import grails.boot.config.GrailsAutoConfiguration
import grails.plugins.metadata.PluginSource
@PluginSource
@CompileStatic
+ @ComponentScan(value = 'example.grails')
class Application extends GrailsAutoConfiguration {
static void main(String[] args) {
GrailsApp.run(Application, args)
}
}
- '''.stripIndent(8)
+ '''
+ }
+
+ void "test generated application scans standard Spring components"() {
+ given:
+ generateProject(OperatingSystem.MACOS_ARCH64)
+ File componentSourceFile = new File(dir, 'src/main/groovy/example/grails/components/ScannedComponent.groovy')
+ componentSourceFile.parentFile.mkdirs()
+ componentSourceFile.text = '''\
+ package example.grails.components
+
+ import org.springframework.stereotype.Component
+
+ @Component
+ class ScannedComponent {
+ String value() {
+ 'scanned'
+ }
+ }
+ '''.stripIndent()
+ File componentSpecFile = new File(dir, 'src/test/groovy/example/grails/ComponentScanningSpec.groovy')
+ componentSpecFile.parentFile.mkdirs()
+ componentSpecFile.text = '''\
+ package example.grails
+
+ import example.grails.components.ScannedComponent
+ import grails.testing.mixin.integration.Integration
+ import org.springframework.beans.factory.annotation.Autowired
+ import spock.lang.Specification
+
+ @Integration
+ class ComponentScanningSpec extends Specification {
+
+ @Autowired
+ ScannedComponent scannedComponent
+
+ void "standard Spring component is injected"() {
+ expect:
+ scannedComponent.value() == 'scanned'
+ }
+ }
+ '''.stripIndent()
+
+ when:
+ String output = executeGradle('test', '--tests', 'example.grails.ComponentScanningSpec').output
+
+ then:
+ output.contains('BUILD SUCCESSFUL')
Review Comment:
Asserting success via console output text is brittle (Gradle output can change with logging level/version). If `executeGradle(...)` exposes an exit status or task outcomes, assert on those instead (e.g., exit code == 0 and/or the `:test` task outcome is `SUCCESS`).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Configure generated applications for component scanning [grails-core]
Posted by "borinquenkid (via GitHub)" <gi...@apache.org>.
borinquenkid commented on PR #16111:
URL: https://github.com/apache/grails-core/pull/16111#issuecomment-5456273758
This PR closes the loop on #14914 by adding `@ComponentScan` to Forge-generated and profile-skeleton `Application` classes, with test coverage across all application types (`WEB`, `REST_API`, `PLUGIN`, `WEB_PLUGIN`) plus an end-to-end TestKit test proving a plain `@Component` bean outside Grails' artefact conventions gets autowired.
Progress on the underlying gating concern (finishing the move off `doWithSpring`/legacy bean loading before turning on component-scan by default) is further along than it may appear: `@GrailsBeans` now compiles bean-wiring into real `@AutoConfiguration` classes, and `grails-core`, `grails-domain-class`, `grails-cache`, `grails-mail`, `grails-sitemesh3`, `grails-url-mappings`, `grails-i18n`, and `grails-databinding` have all migrated.
Still on the legacy `doWithSpring` mechanism: `grails-spring-security` (core, cas, ldap, acl, oauth2, rest-* variants), the Hibernate/Mongo/Neo4j datastore plugins, `grails-quartz`, `grails-gsp`, and `grails-scaffolding`. Worth confirming none of those register a `@Component`/`@Service`-style bean that would now get picked up twice (once via their `doWithSpring` block, once via the new base-package scan) before this leaves draft.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Configure generated applications for component scanning [grails-core]
Posted by "codeconsole (via GitHub)" <gi...@apache.org>.
codeconsole commented on PR #16111:
URL: https://github.com/apache/grails-core/pull/16111#issuecomment-5211948814
Not sure if adding component scanning is a good idea. It's definitely not needed for anything created by the app.
The new bean dsl is a replacement for `resources.groovy`. You can now just specify whatever beans you want in `Application.groovy` in the beans closure.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Configure generated applications for component scanning [grails-core]
Posted by "jdaugherty (via GitHub)" <gi...@apache.org>.
jdaugherty commented on PR #16111:
URL: https://github.com/apache/grails-core/pull/16111#issuecomment-5915179766
I some how missed this PR previously, but I actually agree with @jamesfredley - Grails is supposed to use default configuration and it only scans the package we generate. There's precedence for default annotations being added in GlobalGrailsClassInjectorTransformation already exists. Historically we've added auto configuration where it makes sense, why wouldn't we add ComponentScan in this same case?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@grails.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org