From f7fb495fa95aa682548a1248b241535f7a6d0c94 Mon Sep 17 00:00:00 2001 From: Scott Murphy Heiberg Date: Fri, 20 Sep 2024 21:25:49 -0700 Subject: [PATCH] Groovy 4 for projects, Groovy 3 for Gradle plugins --- .../plugin/core/GrailsGradlePlugin.groovy | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy b/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy index 7f1b5ce6..8dedf668 100644 --- a/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy +++ b/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy @@ -261,22 +261,33 @@ class GrailsGradlePlugin extends GroovyPlugin { protected void configureGroovy(Project project) { final String groovyVersion = project.properties['groovyVersion'] if (groovyVersion) { - project.configurations.all({ Configuration configuration -> - configuration.resolutionStrategy.eachDependency({ DependencyResolveDetails details -> - String dependencyName = details.requested.name - String group = details.requested.group - if (group == 'org.codehaus.groovy') { - if (dependencyName == 'groovy-all') { - details.useTarget "org.apache.groovy:groovy:$groovyVersion" - } else { - details.useTarget "org.apache.groovy:$dependencyName:$groovyVersion" + if (groovyVersion.startsWith("4.")) { + project.configurations.configureEach { Configuration configuration -> + configuration.resolutionStrategy.eachDependency { DependencyResolveDetails details -> + String dependencyName = details.requested.name + String group = details.requested.group + if (group == 'org.codehaus.groovy') { + if (dependencyName == 'groovy-all') { + details.useTarget "org.apache.groovy:groovy:$groovyVersion" + } else { + details.useTarget "org.apache.groovy:$dependencyName:$groovyVersion" + } + details.because("Groovy version substituted for Groovy $groovyVersion") + } else if (group == 'org.apache.groovy' && dependencyName.startsWith('groovy')) { + details.useVersion(groovyVersion) } - details.because('groovy version substituted for groovy 4') - } else if (group == 'org.apache.groovy' && dependencyName.startsWith('groovy')) { - details.useVersion(groovyVersion) } - } as Action) - } as Action) + } + } else if (groovyVersion.startsWith("3.")) { + project.configurations.configureEach { Configuration configuration -> + configuration.resolutionStrategy.eachDependency { DependencyResolveDetails details -> + if ((details.requested.group == 'org.codehaus.groovy' || details.requested.group == 'org.apache.groovy') && details.requested.name != 'groovy-bom') { + details.useTarget(group: 'org.codehaus.groovy', name: details.requested.name, version: "$GroovySystem.version") + details.because "Use Groovy version $GroovySystem.version provided by Gradle" + } + } + } + } } }