jamesfredley commented on code in PR #15467:
URL: https://github.com/apache/grails-core/pull/15467#discussion_r3214125491


##########
grails-gradle/bom-property-overrides/build.gradle:
##########
@@ -0,0 +1,81 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+plugins {
+    id 'groovy'
+    id 'java-gradle-plugin'
+    id 'org.apache.grails.buildsrc.properties'
+    id 'org.apache.grails.buildsrc.dependency-validator'
+    id 'org.apache.grails.buildsrc.compile'
+    id 'org.apache.grails.buildsrc.publish'
+    id 'org.apache.grails.buildsrc.sbom'
+    id 'org.apache.grails.gradle.grails-code-style'
+}
+
+version = projectVersion
+group = 'org.apache.grails'
+
+ext {
+    pomTitle = 'Grails BOM Property Overrides Gradle Plugin'
+    pomDescription = 'A standalone Gradle plugin that enables Maven-style 
property-based version overrides for any Gradle platform() BOM. Reads the BOM 
POM <properties> block and lets consumers override versions via 
gradle.properties or ext[\'property.name\']. Reusable independently of Grails.'
+    pomMavenPublicationName = 'pluginMaven'
+}
+
+dependencies {
+    implementation platform(project(':grails-gradle-bom'))
+
+    // compile with the Groovy version provided by Gradle
+    // see: https://docs.gradle.org/current/userguide/compatibility.html#groovy
+    compileOnly 'org.apache.groovy:groovy'
+
+    // Testing - Gradle TestKit is auto-added by java-gradle-plugin
+    testImplementation('org.spockframework:spock-core') { transitive = false }
+    testImplementation 'org.apache.groovy:groovy-test-junit5'
+    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
+}
+
+configurations {
+    testCompileClasspath.exclude group: 'org.apache.groovy', module: 'groovy'
+    testRuntimeClasspath.exclude group: 'org.apache.groovy', module: 'groovy'
+}
+
+gradlePlugin {
+    plugins {
+        bomPropertyOverrides {
+            displayName = 'Grails BOM Property Overrides Plugin'
+            description = 'Enables Maven-style property-based version 
overrides for any Gradle platform() BOM. ' +
+                    'Apply this plugin and override versions via 
gradle.properties or ext[\'property.name\']. ' +
+                    'Auto-detects declared platform() BOMs by default, or 
accepts an explicit list via the ' +
+                    'bomPropertyOverrides extension.'
+            id = 'org.apache.grails.gradle.bom-property-overrides'
+            implementationClass = 
'org.grails.gradle.plugin.bom.BomPropertyOverridesPlugin'
+        }
+    }
+}
+
+tasks.withType(Copy) {

Review Comment:
   Switched to `tasks.withType(Copy).configureEach { ... }` in 5254097 (and 
dropped the redundant inner `configure { }` block while I was there).



##########
grails-gradle/bom-property-overrides/src/main/groovy/org/grails/gradle/plugin/bom/BomManagedVersions.groovy:
##########
@@ -0,0 +1,378 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.grails.gradle.plugin.bom
+
+import groovy.transform.CompileStatic
+import org.gradle.api.Project
+import org.gradle.api.artifacts.Configuration
+import org.gradle.api.artifacts.DependencyResolveDetails
+import org.gradle.api.logging.Logger
+import org.gradle.api.logging.Logging
+import org.w3c.dom.Document
+import org.w3c.dom.Element
+import org.w3c.dom.NodeList
+
+import javax.xml.parsers.DocumentBuilderFactory
+
+/**
+ * Lightweight replacement for the Spring Dependency Management plugin's
+ * version property override feature.
+ *
+ * <p>Parses BOM POM files to build a mapping of Maven property names
+ * (e.g., {@code slf4j.version}) to the artifacts they control. At
+ * dependency resolution time, checks whether the user has overridden
+ * any of these properties via {@code ext['property.name']} in
+ * {@code build.gradle} or via {@code gradle.properties}, and applies
+ * those overrides using Gradle's {@code 
ResolutionStrategy.eachDependency()}.</p>
+ *
+ * <p>Gradle's native {@code platform()} mechanism handles the base
+ * BOM import and default version management. This class only adds the
+ * one feature Gradle lacks: property-based version customization
+ * (see <a href="https://github.com/gradle/gradle/issues/9160";>Gradle 
#9160</a>).</p>
+ *
+ * <p>This is the underlying utility used by the
+ * {@code org.apache.grails.gradle.bom-property-overrides} plugin. It is
+ * BOM-agnostic and can be used directly with any BOM that follows the
+ * Maven {@code <properties>} convention for managed versions.</p>
+ *
+ * @since 8.0
+ */
+@CompileStatic
+class BomManagedVersions {
+
+    private static final Logger LOG = Logging.getLogger(BomManagedVersions)
+    private static final int MAX_PROPERTY_INTERPOLATION_DEPTH = 10
+
+    private final Map<String, String> versionOverrides = new LinkedHashMap<>()
+
+    /**
+     * Resolves a BOM, parses its POM chain, and determines which managed
+     * dependency versions need to be overridden based on project properties.
+     *
+     * @param project the Gradle project (used for artifact resolution and 
property lookup)
+     * @param bomCoordinates the BOM coordinates in {@code 
group:artifact:version} format
+     * @return a BomManagedVersions instance containing any version overrides 
to apply
+     */
+    static BomManagedVersions resolve(Project project, String bomCoordinates) {
+        return resolve(project, [bomCoordinates])
+    }
+
+    /**
+     * Resolves multiple BOMs, parses their POM chains, and determines which
+     * managed dependency versions need to be overridden based on project
+     * properties. Useful when a project applies several platforms (e.g., a
+     * Grails BOM plus a Micronaut BOM) and any of them may declare overridable
+     * properties.
+     *
+     * @param project the Gradle project (used for artifact resolution and 
property lookup)
+     * @param bomCoordinatesList list of BOM coordinates in {@code 
group:artifact:version} format
+     * @return a BomManagedVersions instance containing any version overrides 
to apply
+     */
+    static BomManagedVersions resolve(Project project, Collection<String> 
bomCoordinatesList) {
+        BomManagedVersions instance = new BomManagedVersions()
+
+        Map<String, String> bomProperties = new LinkedHashMap<>()

Review Comment:
   I see the readability argument, but `BomManagedVersions` is `@CompileStatic` 
and these explicit types are deliberate: with `@CompileStatic` the compiler 
does report missing-method errors at compile time on these locals, but the 
explicit types also document the public contract of `resolve(...)` 
(`Map<String, String>` vs `Map<String, List<String>>` is the key distinction 
the recursive helpers depend on - swapping them would silently produce wrong 
overrides). I'd rather keep the explicit types here for that reason; happy to 
revisit selectively in a follow-up if you want to take a pass at locals that 
are obviously inferable (e.g., `String[] parts`, `Set<String> processed`). 
Leaving open.



##########
grails-gradle/bom-property-overrides/src/main/groovy/org/grails/gradle/plugin/bom/BomPropertyOverridesExtension.groovy:
##########
@@ -0,0 +1,104 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.grails.gradle.plugin.bom
+
+import groovy.transform.CompileStatic
+import org.gradle.api.provider.ListProperty
+import org.gradle.api.provider.Property
+
+/**
+ * Configuration for the
+ * {@code org.apache.grails.gradle.bom-property-overrides} plugin.
+ *
+ * <p>Exposed on the project as {@code bomPropertyOverrides}:</p>
+ *
+ * <pre>
+ * apply plugin: 'org.apache.grails.gradle.bom-property-overrides'
+ *
+ * bomPropertyOverrides {
+ *     // Disable scanning declared platform() dependencies (default: true)
+ *     autoDetect = false
+ *
+ *     // Add explicit BOM coordinates - useful when a BOM is referenced
+ *     // indirectly (e.g., through a parent plugin) and not declared
+ *     // directly via platform() in the consumer's build.gradle
+ *     bom 'org.example:my-bom:1.0.0'
+ *     bom 'org.example:other-bom:2.0.0'
+ * }
+ *
+ * // Override versions via gradle.properties or ext[]
+ * ext['slf4j.version'] = '2.0.13'
+ * </pre>
+ *
+ * <p>By default ({@code autoDetect = true}) the plugin scans every project
+ * configuration for declared {@code platform()} / {@code enforcedPlatform()}
+ * dependencies and registers each unique BOM for property-override
+ * processing. Explicit entries added via {@link #bom(String)} are always
+ * processed in addition to auto-detected ones, regardless of the
+ * {@code autoDetect} flag.</p>
+ *
+ * @since 8.0
+ */
+@CompileStatic
+class BomPropertyOverridesExtension {
+
+    /**
+     * The name of the project extension exposed on every project.
+     */
+    static final String EXTENSION_NAME = 'bomPropertyOverrides'
+
+    /**
+     * Whether to auto-detect BOMs from declared {@code platform()} /
+     * {@code enforcedPlatform()} dependencies on the project's
+     * configurations. Defaults to {@code true}.
+     */
+    final Property<Boolean> autoDetect
+
+    /**
+     * Explicit list of BOM coordinates ({@code group:artifact:version})
+     * that should be processed for property overrides regardless of
+     * whether they are declared as platforms on the project.
+     */
+    final ListProperty<String> boms
+
+    BomPropertyOverridesExtension(org.gradle.api.model.ObjectFactory objects) {

Review Comment:
   Added the `import org.gradle.api.model.ObjectFactory` and dropped the inline 
FQN in 5254097.



##########
grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy:
##########
@@ -360,19 +359,81 @@ ${importStatements}
     protected void applyDefaultPlugins(Project project) {
         applySpringBootPlugin(project)
 

Review Comment:
   Empty line removed in 5254097.



##########
grails-data-graphql/examples/spring-boot-app/build.gradle:
##########
@@ -30,7 +30,6 @@ buildscript {
 apply plugin: 'groovy'
 apply plugin: 'idea'
 apply plugin: 'org.springframework.boot'
-apply plugin: 'io.spring.dependency-management'

Review Comment:
   To clarify what's going on in this hunk: the only line this PR *removes* is 
`apply plugin: 'io.spring.dependency-management'` (consistent with the rest of 
the PR). The `apply plugin: 'org.apache.grails.buildsrc.dependency-validator'` 
line you flagged was already on `8.0.x` before this branch was rebased (it 
landed via 91f3d34 - 'Add task to validate when transitive dependencies force a 
version not matching our bom'); the merge commit 28a6817 picked it up and the 
line was kept while resolving the textual conflict with the Spring DM removal. 
So no change to that line was introduced here. Happy to remove the line 
entirely from this example if you'd prefer the example *not* gain dependency 
validation, but that's an 8.0.x-wide call rather than something this PR needs 
to make. Let me know how you'd like to proceed.



##########
grails-gradle/bom-property-overrides/build.gradle:
##########
@@ -0,0 +1,81 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+plugins {
+    id 'groovy'
+    id 'java-gradle-plugin'
+    id 'org.apache.grails.buildsrc.properties'
+    id 'org.apache.grails.buildsrc.dependency-validator'
+    id 'org.apache.grails.buildsrc.compile'
+    id 'org.apache.grails.buildsrc.publish'
+    id 'org.apache.grails.buildsrc.sbom'
+    id 'org.apache.grails.gradle.grails-code-style'
+}
+
+version = projectVersion
+group = 'org.apache.grails'

Review Comment:
   Could you clarify what change you'd like here? The conventions across all 
the existing `grails-gradle/*` plugins already match this module:
   
   - Maven group: `org.apache.grails` (same as 
`grails-gradle/plugins/build.gradle:32` and `grails-gradle/bom/build.gradle:29`)
   - Subproject path: `:grails-gradle-bom-property-overrides` (matching 
`:grails-gradle-plugins`, `:grails-gradle-bom`, `:grails-gradle-common`, etc., 
per `grails-gradle/settings.gradle`)
   - Plugin id: `org.apache.grails.gradle.bom-property-overrides` (matching 
`org.apache.grails.gradle.grails-app`, `org.apache.grails.gradle.grails-gsp`, 
etc.)
   - Implementation class package: `org.grails.gradle.plugin.bom` (matching 
`org.grails.gradle.plugin.core`, `org.grails.gradle.plugin.views.gsp`, 
`org.grails.gradle.plugin.profiles`, etc.)
   
   If you meant something more specific (e.g. you'd like the Maven group to be 
`org.apache.grails.gradle` for the gradle plugins family - which would diverge 
from every other `grails-gradle/*` module on `8.0.x`), happy to pick that up - 
it'd just need to be a coordinated change across all the gradle plugin modules 
in a separate PR. Leaving open until I hear back.



##########
grails-gradle/bom-property-overrides/build.gradle:
##########
@@ -0,0 +1,81 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+plugins {
+    id 'groovy'
+    id 'java-gradle-plugin'
+    id 'org.apache.grails.buildsrc.properties'
+    id 'org.apache.grails.buildsrc.dependency-validator'
+    id 'org.apache.grails.buildsrc.compile'
+    id 'org.apache.grails.buildsrc.publish'
+    id 'org.apache.grails.buildsrc.sbom'
+    id 'org.apache.grails.gradle.grails-code-style'
+}
+
+version = projectVersion
+group = 'org.apache.grails'
+
+ext {
+    pomTitle = 'Grails BOM Property Overrides Gradle Plugin'
+    pomDescription = 'A standalone Gradle plugin that enables Maven-style 
property-based version overrides for any Gradle platform() BOM. Reads the BOM 
POM <properties> block and lets consumers override versions via 
gradle.properties or ext[\'property.name\']. Reusable independently of Grails.'
+    pomMavenPublicationName = 'pluginMaven'
+}
+
+dependencies {
+    implementation platform(project(':grails-gradle-bom'))
+
+    // compile with the Groovy version provided by Gradle
+    // see: https://docs.gradle.org/current/userguide/compatibility.html#groovy
+    compileOnly 'org.apache.groovy:groovy'
+
+    // Testing - Gradle TestKit is auto-added by java-gradle-plugin
+    testImplementation('org.spockframework:spock-core') { transitive = false }
+    testImplementation 'org.apache.groovy:groovy-test-junit5'
+    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
+}
+
+configurations {
+    testCompileClasspath.exclude group: 'org.apache.groovy', module: 'groovy'

Review Comment:
   Same answer as matrei's neighbouring thread - this matches the convention 
already in `grails-gradle/plugins/build.gradle:67-68`. The `compileOnly 
'org.apache.groovy:groovy'` declaration above means we compile against the 
Groovy version that Gradle ships in the running distribution; at test time 
however Spock pulls a transitive `org.apache.groovy:groovy` (Spock 
2.3-groovy-4.0 → groovy-4.0.x) which would otherwise be on 
`testCompileClasspath`/`testRuntimeClasspath` simultaneously with the 
Gradle-supplied Groovy. The hard excludes pin testing to the Gradle-bundled 
Groovy, which is what `groovy-test-junit5` actually runs against. I expanded 
the comment block above the `compileOnly` declaration in 5254097 to spell this 
out. If you'd like me to lift the exclude into a shared convention plugin so we 
don't repeat it across every gradle-plugin module, that's a reasonable cleanup 
but probably belongs in a separate PR. Leaving open.



##########
grails-gradle/bom-property-overrides/build.gradle:
##########
@@ -0,0 +1,81 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+plugins {
+    id 'groovy'
+    id 'java-gradle-plugin'
+    id 'org.apache.grails.buildsrc.properties'
+    id 'org.apache.grails.buildsrc.dependency-validator'
+    id 'org.apache.grails.buildsrc.compile'
+    id 'org.apache.grails.buildsrc.publish'
+    id 'org.apache.grails.buildsrc.sbom'
+    id 'org.apache.grails.gradle.grails-code-style'
+}
+
+version = projectVersion
+group = 'org.apache.grails'
+
+ext {
+    pomTitle = 'Grails BOM Property Overrides Gradle Plugin'
+    pomDescription = 'A standalone Gradle plugin that enables Maven-style 
property-based version overrides for any Gradle platform() BOM. Reads the BOM 
POM <properties> block and lets consumers override versions via 
gradle.properties or ext[\'property.name\']. Reusable independently of Grails.'
+    pomMavenPublicationName = 'pluginMaven'
+}
+
+dependencies {
+    implementation platform(project(':grails-gradle-bom'))
+
+    // compile with the Groovy version provided by Gradle
+    // see: https://docs.gradle.org/current/userguide/compatibility.html#groovy
+    compileOnly 'org.apache.groovy:groovy'
+
+    // Testing - Gradle TestKit is auto-added by java-gradle-plugin
+    testImplementation('org.spockframework:spock-core') { transitive = false }
+    testImplementation 'org.apache.groovy:groovy-test-junit5'
+    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
+}
+
+configurations {
+    testCompileClasspath.exclude group: 'org.apache.groovy', module: 'groovy'
+    testRuntimeClasspath.exclude group: 'org.apache.groovy', module: 'groovy'
+}
+
+gradlePlugin {
+    plugins {
+        bomPropertyOverrides {
+            displayName = 'Grails BOM Property Overrides Plugin'
+            description = 'Enables Maven-style property-based version 
overrides for any Gradle platform() BOM. ' +
+                    'Apply this plugin and override versions via 
gradle.properties or ext[\'property.name\']. ' +
+                    'Auto-detects declared platform() BOMs by default, or 
accepts an explicit list via the ' +
+                    'bomPropertyOverrides extension.'
+            id = 'org.apache.grails.gradle.bom-property-overrides'
+            implementationClass = 
'org.grails.gradle.plugin.bom.BomPropertyOverridesPlugin'
+        }
+    }
+}
+
+tasks.withType(Copy) {
+    configure {
+        duplicatesStrategy = DuplicatesStrategy.INCLUDE

Review Comment:
   Honestly: I copied this block from 
`grails-gradle/plugins/build.gradle:142-146` (which has had it since the 
original Spring-DM-era setup) without re-deriving the underlying duplicate. 
After your comment I tried removing the block locally and 
`:grails-gradle-bom-property-overrides:assemble` passes - so it likely *isn't* 
needed for this module. I left it in 5254097 only to keep the 
bom-property-overrides module structurally identical to the existing plugins 
module rather than have it diverge in a confusing way; if you'd like I can drop 
the block here AND from `grails-gradle/plugins/build.gradle` in a follow-up 
commit on this PR (or as a separate cleanup), whichever you prefer. Open until 
you weigh in.



-- 
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]

Reply via email to