jamesfredley commented on code in PR #15467:
URL: https://github.com/apache/grails-core/pull/15467#discussion_r3342081591
##########
grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy:
##########
@@ -367,36 +366,111 @@ ${importStatements}
protected void applyDefaultPlugins(Project project) {
applySpringBootPlugin(project)
+ applyGrailsBom(project)
+ }
+ /**
+ * Applies the Grails BOM as a Gradle platform and enables property-based
+ * version overrides via the standalone
+ * {@code org.apache.grails.gradle.bom-property-overrides} plugin.
+ *
+ * <p>This replaces the Spring Dependency Management plugin with two
+ * orthogonal pieces:</p>
+ * <ol>
+ * <li><strong>BOM import</strong>: {@code grails-bom} is added as a
+ * Gradle {@code platform()} dependency on every declarable
+ * configuration, mirroring the global behaviour Spring DM provided
+ * via {@code configurations.all() +
resolutionStrategy.eachDependency()}.</li>
+ * <li><strong>Property overrides</strong>: the BOM-agnostic
+ * {@link BomPropertyOverridesPlugin} reads the BOM's
+ * {@code <properties>} block and applies any project-level
+ * overrides via Gradle's
+ * {@code ResolutionStrategy.eachDependency()}.</li>
+ * </ol>
+ *
+ * <p>Usage: to override a version managed by the Grails or Spring Boot
BOM, set the
+ * corresponding property in {@code gradle.properties} or {@code
build.gradle}:</p>
+ * <pre>
+ * // gradle.properties
+ * slf4j.version=1.7.36
+ *
+ * // or build.gradle
+ * ext['slf4j.version'] = '1.7.36'
+ * </pre>
+ *
+ * @see BomPropertyOverridesPlugin
+ * @since 8.0
+ */
+ protected void applyGrailsBom(Project project) {
+ // Ensure the developmentOnly configuration exists. Spring Boot's
plugin
+ // normally creates this, but using maybeCreate guarantees it is
available
+ // even if plugin ordering changes or Spring Boot is not applied. We do
+ // this outside afterEvaluate so that other plugins applied during the
+ // same configuration phase can rely on the configuration existing.
+ project.configurations.maybeCreate('developmentOnly')
+
+ // The opt-out flag `grails { autoApplyBom = false }` is set in the
user's
+ // build.gradle, which runs AFTER plugin apply. We therefore wait until
+ // afterEvaluate to read the flag and apply the BOM accordingly. By
that
+ // point all declarable configurations exist (java-base creates them
+ // during apply), so iterating them eagerly via .each is sufficient -
+ // any plugin that adds a configuration later is responsible for
+ // declaring its own BOM coordination if it needs it.
project.afterEvaluate {
- GrailsExtension ge = project.extensions.getByType(GrailsExtension)
- if (ge.springDependencyManagement) {
- Plugin dependencyManagementPlugin =
project.plugins.findPlugin(DependencyManagementPlugin)
- if (dependencyManagementPlugin == null) {
- project.plugins.apply(DependencyManagementPlugin)
- }
-
- DependencyManagementExtension dme =
project.extensions.findByType(DependencyManagementExtension)
+ GrailsExtension grailsExtension =
project.extensions.findByType(GrailsExtension)
+ boolean autoApply = grailsExtension == null ||
grailsExtension.autoApplyBom.getOrElse(true)
+ if (!autoApply) {
+ project.logger.info(
+ 'grails.autoApplyBom is false; skipping automatic
application of platform(grails-bom) and bom-property-overrides plugin for
project {}',
+ project.path
+ )
+ return
+ }
- applyBomImport(dme, project)
+ String grailsVersion = (project.findProperty('grailsVersion') ?:
BuildSettings.grailsVersion) as String
+ String bomCoordinates =
"org.apache.grails:grails-bom:${grailsVersion}" as String
Review Comment:
Done in c2ac4a6948 - `grailsVersion` and `bomCoordinates` now use `def`.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]