Skip to content

Commit 6c1bc8c

Browse files
authored
feat!: Update to Groovy 4 (#13532)
1 parent 34bba33 commit 6c1bc8c

File tree

85 files changed

+3450
-2849
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+3450
-2849
lines changed

.github/workflows/groovy-joint-workflow.yml

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,33 +40,37 @@ jobs:
4040
- name: Set up JDK
4141
uses: actions/setup-java@v4
4242
with:
43-
distribution: 'adopt'
44-
java-version: '11.0.6'
43+
distribution: temurin
44+
java-version: 17
4545
- name: Cache local Maven repository & Groovy
4646
uses: actions/cache@v4
4747
with:
4848
path: |
4949
~/groovy
5050
~/.m2/repository
5151
key: cache-local-groovy-maven-${{ github.sha }}
52-
- name: Checkout Groovy 3_0_X (Grails 5 and later)
53-
if: startsWith(github.ref, 'refs/heads/7.') || startsWith(github.base_ref, '7.') || startsWith(github.ref, 'refs/heads/6.') || startsWith(github.base_ref, '6.') || startsWith(github.ref, 'refs/heads/5.') || startsWith(github.base_ref, '5.')
54-
run: cd .. && git clone --depth 1 https://github.com/apache/groovy.git -b GROOVY_3_0_X --single-branch
52+
- name: Checkout Groovy 4_0_X (Grails 7 and later)
53+
run: cd .. && git clone --depth 1 https://github.com/apache/groovy.git -b GROOVY_4_0_X --single-branch
5554
- name: Set CI_GROOVY_VERSION for Grails
5655
id: groovy-version
5756
run: |
5857
cd ../groovy
5958
echo "CI_GROOVY_VERSION=$(cat gradle.properties | grep groovyVersion | cut -d\= -f2 | tr -d '[:space:]')" >> $GITHUB_ENV
6059
echo "value=$(cat gradle.properties | grep groovyVersion | cut -d\= -f2 | tr -d '[:space:]')" >> $GITHUB_OUTPUT
61-
- name: Prepare GE Set-up Configuration
62-
id: ge_conf
60+
- name: Prepare Develocity Setup 1
61+
id: develocity_conf_1
6362
run: |
6463
echo "VALUE<<EOF" >> $GITHUB_OUTPUT
6564
echo "plugins { " >> $GITHUB_OUTPUT
6665
echo " id 'com.gradle.enterprise' version '3.15.1'" >> $GITHUB_OUTPUT
6766
echo " id 'com.gradle.common-custom-user-data-gradle-plugin' version '1.11.3'" >> $GITHUB_OUTPUT
6867
echo "}" >> $GITHUB_OUTPUT
6968
echo "" >> $GITHUB_OUTPUT
69+
echo "EOF" >> $GITHUB_OUTPUT
70+
- name: Prepare Develocity Setup 2
71+
id: develocity_conf_2
72+
run: |
73+
echo "VALUE<<EOF" >> $GITHUB_OUTPUT
7074
echo "gradleEnterprise {" >> $GITHUB_OUTPUT
7175
echo " server = 'https://ge.grails.org'" >> $GITHUB_OUTPUT
7276
echo " buildScan {" >> $GITHUB_OUTPUT
@@ -93,13 +97,17 @@ jobs:
9397
echo "}" >> $GITHUB_OUTPUT
9498
echo "" >> $GITHUB_OUTPUT
9599
echo "EOF" >> $GITHUB_OUTPUT
96-
- name: Gradle Enterprise Set-up
100+
- name: Develocity Set-up
97101
run: |
98102
cd ../groovy
99-
# Delete exiting plugins and build-scan from settings.gradle file
100-
sed -i '21,31d' settings.gradle
101-
# Add Gradle Enterprise set-up related configuration after line no 20 in settings.gradle
102-
echo "${{ steps.ge_conf.outputs.value}}" | sed -i -e "20r /dev/stdin" settings.gradle
103+
# Delete existing plugins from settings.gradle file
104+
sed -i '32,37d' settings.gradle
105+
# Add Gradle Enterprise set-up related configuration after line no 31 in settings.gradle
106+
echo "${{ steps.develocity_conf_1.outputs.value }}" | sed -i -e "31r /dev/stdin" settings.gradle
107+
# Delete existing buildCache configuration from gradle/build-scans.gradle file
108+
sed -i '23,46d' gradle/build-scans.gradle
109+
# Add Gradle Enterprise set-up related configuration after line no 22 in gradle/build-scans.gradle
110+
echo "${{ steps.develocity_conf_2.outputs.value }}" | sed -i -e "22r /dev/stdin" gradle/build-scans.gradle
103111
- name: Build and install groovy (no docs)
104112
uses: gradle/gradle-build-action@v3
105113
env:
@@ -127,8 +135,8 @@ jobs:
127135
- name: Set up JDK
128136
uses: actions/setup-java@v4
129137
with:
130-
distribution: 'adopt'
131-
java-version: '17'
138+
distribution: temurin
139+
java-version: 17
132140
- name: Cache local Maven repository & Groovy
133141
uses: actions/cache@v4
134142
with:

build.gradle

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ ext {
8484
modules: ['']
8585
],
8686
'groovy' : [version: groovyVersion,
87-
group : 'org.codehaus.groovy',
87+
group : 'org.apache.groovy',
8888
names : ['groovy'],
8989
modules: ['', 'xml', 'swing', 'console', 'json', 'ant', 'sql', 'templates', 'nio', 'dateutil', 'macro']
9090
],
@@ -189,9 +189,9 @@ if (jointBuildGroovyJarProperty) {
189189
throw new GradleException("The groovy.jar system property points to ${jointBuildGroovyJar.absolutePath} which does not exist.")
190190
}
191191
} else {
192-
groovyDependency = dependencies.create("org.codehaus.groovy:groovy:${groovyVersion}") {
193-
exclude module: "commons-cli"
194-
exclude module: "ant"
192+
groovyDependency = dependencies.create("org.apache.groovy:groovy:${groovyVersion}") {
193+
exclude module:"commons-cli"
194+
exclude module:"ant"
195195
}
196196
}
197197

@@ -220,15 +220,25 @@ if (isReleaseVersion) {
220220
}
221221

222222
allprojects {
223+
224+
// FORCE UPGRADE OF GROOVY IN DEPENDENCIES TO GROOVY 4
225+
configurations.configureEach {
226+
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
227+
if (details.requested.group == 'org.codehaus.groovy' && details.requested.name != 'groovy-bom') {
228+
details.useTarget(group: 'org.apache.groovy', name: details.requested.name, version: groovyVersion)
229+
}
230+
}
231+
}
232+
223233
repositories {
224234
mavenLocal()
225235
mavenCentral()
226-
maven { url "https://repo.grails.org/grails/core" }
227-
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
228-
if (groovyVersion.endsWith('-SNAPSHOT')) {
236+
maven { url = 'https://repo.grails.org/grails/core' }
237+
maven { url = 'https://oss.sonatype.org/content/repositories/snapshots' }
238+
if(groovyVersion.endsWith('-SNAPSHOT')) {
229239
maven {
230-
name 'JFrog OSS snapshot repo'
231-
url 'https://oss.jfrog.org/oss-snapshot-local/'
240+
name = 'ASF Snapshot repo'
241+
url = 'https://repository.apache.org/content/repositories/snapshots'
232242
}
233243
}
234244
}
@@ -241,7 +251,7 @@ allprojects {
241251
cacheChangingModulesFor cacheHours, 'hours'
242252
eachDependency { DependencyResolveDetails details ->
243253
//specifying a fixed version for all libraries with 'org.gradle' group
244-
if (details.requested.group == 'org.codehaus.groovy') {
254+
if (details.requested.group == 'org.apache.groovy') {
245255
details.useVersion(groovyVersion)
246256
}
247257
if (details.requested.group == "org.spockframework") {
@@ -472,15 +482,15 @@ subprojects { project ->
472482
}
473483

474484
dependencies {
475-
documentation "org.fusesource.jansi:jansi:$jansiVersion"
476-
documentation "jline:jline:$jlineVersion"
477-
documentation "org.codehaus.groovy:groovy-ant:$groovyVersion"
478-
documentation "org.codehaus.groovy:groovy-cli-picocli:$groovyVersion"
479-
documentation "com.github.javaparser:javaparser-core:$javaParserCoreVersion"
485+
documentation("org.fusesource.jansi:jansi:$jansiVersion")
486+
documentation("jline:jline:$jlineVersion")
487+
documentation "org.apache.groovy:groovy-ant:$groovyVersion"
488+
documentation "org.apache.groovy:groovy-cli-picocli:$groovyVersion"
489+
documentation ("com.github.javaparser:javaparser-core:$javaParserCoreVersion")
480490

481491
api groovyDependency
482492

483-
testImplementation "org.codehaus.groovy:groovy-test-junit5:${groovyVersion}"
493+
testImplementation "org.apache.groovy:groovy-test-junit5:${groovyVersion}"
484494
testImplementation "org.junit.jupiter:junit-jupiter-api:5.10.2"
485495
testImplementation "org.junit.platform:junit-platform-runner:1.10.2"
486496
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.10.2"

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ feildsPluginVersion=5.0.2
1111
gdocEngineVersion=1.0.1
1212
gradleNexusPluginVersion=2.3.1
1313
gradleNexusStagingPluginVersion=0.12.0
14-
groovyVersion=3.0.21
14+
groovyVersion=4.0.22
1515
gspVersion=6.2.1
1616
h2.version=2.2.224
1717
h2Version=2.2.224
@@ -38,7 +38,7 @@ scaffoldingCoreVersion=2.1.0
3838
servletApiVersion=4.0.1
3939
slf4jVersion=1.7.36
4040
snakeyamlVersion=2.2
41-
spockVersion=2.1-groovy-3.0
41+
spockVersion=2.3-groovy-4.0
4242
springBootVersion=2.7.18
4343
springLoadedVersion=1.2.8.RELEASE
4444
springVersion=5.3.33

gradle/docs.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ configurations {
1717
}
1818

1919
dependencies {
20-
documentation "org.codehaus.groovy:groovy-groovydoc:$groovyVersion"
20+
documentation "org.apache.groovy:groovy-groovydoc:$groovyVersion"
2121
}
2222

2323
ext.grailsDocSrc = project.findProperty('grails-doc.home') ?: project.buildDir.absolutePath + "/checkout/grails-docs-src"

grails-bom/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ publishing {
6161
mkp.artifactId 'jna'
6262
}
6363
mkp.exclusion {
64-
mkp.groupId 'org.codehaus.groovy'
64+
mkp.groupId 'org.apache.groovy'
6565
mkp.artifactId 'groovy-ant'
6666
}
6767
}

grails-bootstrap/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import org.apache.tools.ant.filters.ReplaceTokens
22

33
dependencies {
4-
api ( "org.codehaus.groovy:groovy-xml:$groovyVersion" )
5-
api ( "org.codehaus.groovy:groovy-templates:$groovyVersion" )
4+
api ( "org.apache.groovy:groovy-xml:$groovyVersion" )
5+
api ( "org.apache.groovy:groovy-templates:$groovyVersion" )
66
api "org.yaml:snakeyaml"
77
api "io.micronaut:micronaut-inject:$micronautVersion"
88

@@ -12,7 +12,7 @@ dependencies {
1212
compileOnly("net.java.dev.jna:jna:$jnaVersion")
1313

1414
// Ant
15-
compileOnly "org.codehaus.groovy:groovy-ant:$groovyVersion"
15+
compileOnly "org.apache.groovy:groovy-ant:$groovyVersion"
1616

1717
testImplementation("org.fusesource.jansi:jansi:$jansiVersion")
1818
testImplementation("jline:jline:$jlineVersion")

grails-bootstrap/src/main/groovy/grails/util/Environment.groovy

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2004-2005 the original author or authors.
2+
* Copyright 2004-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -57,6 +57,10 @@ enum Environment {
5757
/** A custom environment */
5858
CUSTOM
5959

60+
/**
61+
* Initialize the Logger lazily because:
62+
* https://github.com/grails/grails-core/issues/11476
63+
*/
6064
private static final Supplier<Logger> LOG = SupplierUtil.memoized(() -> LoggerFactory.getLogger(Environment.class))
6165

6266
/**
@@ -120,9 +124,9 @@ enum Environment {
120124

121125
@SuppressWarnings("unchecked")
122126
private static Map<String, String> envNameMappings = CollectionUtils.<String, String> newMap(
123-
DEVELOPMENT_ENVIRONMENT_SHORT_NAME, Environment.DEVELOPMENT.getName(),
124-
PRODUCTION_ENV_SHORT_NAME, Environment.PRODUCTION.getName(),
125-
TEST_ENVIRONMENT_SHORT_NAME, Environment.TEST.getName())
127+
DEVELOPMENT_ENVIRONMENT_SHORT_NAME, DEVELOPMENT.getName(),
128+
PRODUCTION_ENV_SHORT_NAME, PRODUCTION.getName(),
129+
TEST_ENVIRONMENT_SHORT_NAME, TEST.getName())
126130
private static Holder<Environment> cachedCurrentEnvironment = new Holder<>("Environment")
127131
private static final boolean DEVELOPMENT_MODE = getCurrent() == DEVELOPMENT && BuildSettings.GRAILS_APP_DIR_PRESENT
128132
private static Boolean RELOADING_AGENT_ENABLED = null
@@ -295,14 +299,14 @@ enum Environment {
295299
Environment env = getEnvironment(envName)
296300
if (env == null) {
297301
try {
298-
env = Environment.valueOf(envName.toUpperCase())
302+
env = valueOf(envName.toUpperCase())
299303
}
300304
catch (IllegalArgumentException e) {
301305
// ignore
302306
}
303307
}
304308
if (env == null) {
305-
env = Environment.CUSTOM
309+
env = CUSTOM
306310
env.setName(envName)
307311
}
308312
return env
@@ -355,7 +359,7 @@ enum Environment {
355359
* @return True if the development sources are present
356360
*/
357361
static boolean isDevelopmentRun() {
358-
Environment env = Environment.getCurrent()
362+
Environment env = getCurrent()
359363
return isDevelopmentEnvironmentAvailable() && Boolean.getBoolean(RUN_ACTIVE) && (env == Environment.DEVELOPMENT)
360364
}
361365

@@ -368,7 +372,7 @@ enum Environment {
368372
LOG.get().debug("Looking for pid file at: {}", pidFile)
369373
boolean isDevToolsRestart = false
370374
try {
371-
if (Environment.isDevelopmentMode()) {
375+
if (isDevelopmentMode()) {
372376
String pid = ManagementFactory.getRuntimeMXBean().getName()
373377
if (pidFile.exists()) {
374378
if (pid.equals(Files.readAllLines(pidFile.toPath()).get(0))) {
@@ -479,10 +483,10 @@ enum Environment {
479483
static Environment getEnvironment(String shortName) {
480484
final String envName = envNameMappings.get(shortName)
481485
if (envName != null) {
482-
return Environment.valueOf(envName.toUpperCase())
486+
return valueOf(envName.toUpperCase())
483487
} else {
484488
try {
485-
return Environment.valueOf(shortName.toUpperCase())
489+
return valueOf(shortName.toUpperCase())
486490
} catch (IllegalArgumentException ise) {
487491
return null
488492
}
@@ -646,7 +650,7 @@ enum Environment {
646650
}
647651
try {
648652
Class.forName("org.springframework.boot.devtools.RemoteSpringApplication")
649-
RELOADING_AGENT_ENABLED = Environment.getCurrent().isReloadEnabled()
653+
RELOADING_AGENT_ENABLED = getCurrent().isReloadEnabled()
650654
LOG.get().debug("Found spring-dev-tools on the class path")
651655
}
652656
catch (ClassNotFoundException e) {
@@ -655,7 +659,7 @@ enum Environment {
655659
Class.forName("org.springsource.loaded.TypeRegistry")
656660
String jvmVersion = System.getProperty("java.specification.version")
657661
LOG.get().debug("Found spring-loaded on the class path")
658-
RELOADING_AGENT_ENABLED = Environment.getCurrent().isReloadEnabled()
662+
RELOADING_AGENT_ENABLED = getCurrent().isReloadEnabled()
659663
}
660664
catch (ClassNotFoundException e1) {
661665
RELOADING_AGENT_ENABLED = false
@@ -712,8 +716,8 @@ enum Environment {
712716
}
713717

714718
private static String getEnvironmentInternal() {
715-
String envName = System.getProperty(Environment.KEY)
716-
return isBlank(envName) ? System.getenv(Environment.ENV_KEY) : envName
719+
String envName = System.getProperty(KEY)
720+
return isBlank(envName) ? System.getenv(ENV_KEY) : envName
717721
}
718722

719723
}

grails-bootstrap/src/main/groovy/grails/util/Metadata.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2004-2005 the original author or authors.
2+
* Copyright 2004-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -360,7 +360,7 @@ class Metadata extends PropertySourcePropertyResolver {
360360
return ((PropertyResolver) this).getProperty(key.toString(), Object).orElse(defaultValue)
361361
}
362362

363-
static class FinalReference<T> extends SoftReference<T> {
363+
final static class FinalReference<T> extends SoftReference<T> {
364364
private final T ref
365365

366366
FinalReference(T t) {

grails-bootstrap/src/main/groovy/org/grails/io/support/SpringIOUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2008 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
1515
*/
1616
package org.grails.io.support;
1717

18-
import groovy.util.XmlSlurper;
18+
import groovy.xml.XmlSlurper;
1919
import groovy.xml.FactorySupport;
2020
import org.xml.sax.SAXException;
2121
import javax.xml.XMLConstants;

grails-bootstrap/src/test/groovy/grails/io/IOUtilsSpec.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ class IOUtilsSpec extends Specification{
1212
IOUtils.findClassResource(BuildSettings).path.contains('grails-bootstrap')
1313
}
1414

15-
void "Test findJarResource finds a the JAR resource"() {
15+
void "Test findJarResource finds a JAR resource"() {
1616
expect:
1717
IOUtils.findJarResource(Specification)
18-
IOUtils.findJarResource(Specification).path.endsWith('spock-core-2.1-groovy-3.0.jar!/')
18+
IOUtils.findJarResource(Specification).path.endsWith('spock-core-2.3-groovy-4.0.jar!/')
1919
}
2020
}

0 commit comments

Comments
 (0)