This is an automated email from the ASF dual-hosted git repository.

jamesfredley pushed a commit to branch gradle-module-variant
in repository https://gitbox.apache.org/repos/asf/grails-core.git

commit 81b2bf37803e39a8e95f8ac844d104bd9f991e40
Author: James Fredley <[email protected]>
AuthorDate: Mon Aug 25 17:52:22 2025 -0400

    Add profile support for Gradle dependency variants
    
    Enhanced ProfileUtil and GradleDependency to support Gradle dependency 
variants (e.g., platform()) in profile definitions. Updated profile.yml files 
to move variant and devtools dependencies from build.gradle into the profile 
metadata, and added integration test dependency to the web profile. This change 
improves consistency and flexibility in dependency management for Grails 
profiles.
---
 grails-profiles/base/profile.yml                   |  4 ++++
 grails-profiles/base/skeleton/build.gradle         |  3 ---
 grails-profiles/web/profile.yml                    |  2 ++
 .../org/grails/cli/profile/ProfileUtil.groovy      | 23 ++++++++++++++++++----
 .../profile/commands/io/GradleDependency.groovy    | 21 +++++++++++---------
 5 files changed, 37 insertions(+), 16 deletions(-)

diff --git a/grails-profiles/base/profile.yml b/grails-profiles/base/profile.yml
index daaa9dfab2..f150003a5f 100644
--- a/grails-profiles/base/profile.yml
+++ b/grails-profiles/base/profile.yml
@@ -31,6 +31,10 @@ build:
 dependencies:
     - scope: build
       coords: "org.apache.grails:grails-gradle-plugins"
+    - scope: developmentOnly
+      coords: "org.springframework.boot:spring-boot-devtools"
+    - scope: implementation
+      coords: 'platform("org.apache.grails:grails-bom:$grailsVersion")'
     - scope: implementation
       coords: "org.springframework.boot:spring-boot-starter-logging"
     - scope: implementation
diff --git a/grails-profiles/base/skeleton/build.gradle 
b/grails-profiles/base/skeleton/build.gradle
index df46cc4114..52fa0720c3 100644
--- a/grails-profiles/base/skeleton/build.gradle
+++ b/grails-profiles/base/skeleton/build.gradle
@@ -32,9 +32,6 @@ repositories {
 }
 
 dependencies {
-    implementation platform("org.apache.grails:grails-bom:$grailsVersion")
-    developmentOnly "org.springframework.boot:spring-boot-devtools" // Spring 
Boot DevTools may cause performance slowdowns or compatibility issues on larger 
applications
-    integrationTestImplementation testFixtures("org.apache.grails:grails-geb")
 @dependencies@
 }
 
diff --git a/grails-profiles/web/profile.yml b/grails-profiles/web/profile.yml
index 3a79937638..bc8d2f0d97 100644
--- a/grails-profiles/web/profile.yml
+++ b/grails-profiles/web/profile.yml
@@ -57,3 +57,5 @@ dependencies:
       coords: "org.webjars.npm:bootstrap-icons"
     - scope: testAndDevelopmentOnly
       coords: "org.webjars.npm:jquery"
+    - scope: integrationTestImplementation
+      coords: 'testFixtures("org.apache.grails:grails-geb")'
diff --git 
a/grails-shell-cli/src/main/groovy/org/grails/cli/profile/ProfileUtil.groovy 
b/grails-shell-cli/src/main/groovy/org/grails/cli/profile/ProfileUtil.groovy
index 3ebd0c5550..d1206b710f 100644
--- a/grails-shell-cli/src/main/groovy/org/grails/cli/profile/ProfileUtil.groovy
+++ b/grails-shell-cli/src/main/groovy/org/grails/cli/profile/ProfileUtil.groovy
@@ -32,10 +32,25 @@ import org.eclipse.aether.graph.Exclusion
 class ProfileUtil {
 
     static Dependency createDependency(String coords, String scope, Map 
configEntry) {
-        if (coords.count(':') == 1) {
-            coords = "$coords:BOM"
+        String variant = null
+        String inner = coords?.trim()
+
+        if (inner) {
+            // Detect variants like someVariant("group:artifact[:version]")
+            def m = inner =~ 
/^\s*([A-Za-z_][A-Za-z0-9_]*)\s*\(\s*["'](.+?)["']\s*\)\s*$/
+            if (m.matches()) {
+                variant = m[0][1]
+                inner = m[0][2]
+            }
+        }
+
+        // Append a placeholder version when only group:artifact provided
+        if (inner?.count(':') == 1) {
+            inner = "$inner:BOM"
         }
-        Dependency dependency = new Dependency(new DefaultArtifact(coords), 
scope.toString())
+
+        Dependency dependency = new Dependency((variant ? new 
DefaultArtifact(inner, ['variant': variant]) : new DefaultArtifact(inner)), 
scope.toString())
+
         if (configEntry.containsKey('excludes')) {
             List<Exclusion> dependencyExclusions = new ArrayList<>()
             List excludes = (List) configEntry.excludes
@@ -46,6 +61,6 @@ class ProfileUtil {
             }
             dependency = dependency.setExclusions(dependencyExclusions)
         }
-        dependency
+        return dependency
     }
 }
diff --git 
a/grails-shell-cli/src/main/groovy/org/grails/cli/profile/commands/io/GradleDependency.groovy
 
b/grails-shell-cli/src/main/groovy/org/grails/cli/profile/commands/io/GradleDependency.groovy
index a3afd960b1..5f776e0a87 100644
--- 
a/grails-shell-cli/src/main/groovy/org/grails/cli/profile/commands/io/GradleDependency.groovy
+++ 
b/grails-shell-cli/src/main/groovy/org/grails/cli/profile/commands/io/GradleDependency.groovy
@@ -47,23 +47,26 @@ class GradleDependency {
         this.scope = scope
         def artifact = dependency.artifact
         def v = artifact.version.replace('BOM', '')
+        String groupArtifactVersion = artifact.groupId + ':' + 
artifact.artifactId + (v ? ':' + v : '')
+
+        String variantCall
+        String variant = artifact.properties?.'variant'
+        if (variant) {
+            variantCall = "${variant}(\"${groupArtifactVersion}\")"
+        }
+
         StringBuilder artifactString = new StringBuilder()
-        if (dependency.exclusions != null && !dependency.exclusions.empty) {
+        boolean hasExclusions = (dependency.exclusions != null && 
!dependency.exclusions.empty)
+        if (hasExclusions) {
             artifactString.append('(')
         } else {
             artifactString.append(' ')
         }
-        artifactString.append('"')
-        artifactString.append(artifact.groupId)
-        artifactString.append(':').append(artifact.artifactId)
-        if (v) {
-            artifactString.append(':').append(v)
-        }
-        artifactString.append('"')
+        artifactString.append(variantCall ?: '"' + groupArtifactVersion + '"')
 
         def ln = System.getProperty("line.separator")
 
-        if (dependency.exclusions != null && !dependency.exclusions.empty) {
+        if (hasExclusions) {
             artifactString.append(") {").append(ln)
             for (e in dependency.exclusions) {
                 artifactString.append("    ")

Reply via email to