HowTo: run the Groovy tests locally with the latest Groovy version

For those who may want to run the Groovy tests locally with the latest Groovy version and may be having problems, there have been some changes.

First, if using Groovy 4.0+, with the latest Java version, then install the latest Gradle version by setting the distributionUrl in the gradle-wrapper.properties file accordingly

distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip

The Gradle version for the Java version being used can be found at the Compatibility Matrix. Most likely, if using Groovy version 4.0+, then Java 19+ is being used.

The spock-core for Groovy version 4.0+ is now 2.4-M1-groovy-4.0 for testImplementation in the build.gradle file.

testImplementation "org.spockframework:spock-core:2.4-M1-groovy-4.0"

With Groovy version 4.0+ codehaus is now replaced by apache for the implementation, and the groovy-all is the current Groovy version.

implementation "org.apache.groovy:groovy-all:4.0.8"

dependencies {
    testImplementation "org.spockframework:spock-core:2.4-M1-groovy-4.0"
    implementation "org.apache.groovy:groovy-all:4.0.8"
}

Here is a link to all of the supported spock-core versions

I’ve only gone through this reconfiguration with the Isogram Exercise. If other exercises have issues, I’m unaware of them.

3 Likes

I installed Gradle, Java, and Groovy locally and configured them as environment variables. It’s important to note that Groovy (Apache) needs JAVA_HOME, which is configured in PATH as %JAVA_HOME%/bin.

To run tests via gradlew, you need Java 11. I tried versions 17 and 22, but both are not compatible. After consulting Phind AI, it was mentioned to use Java 11, and it works! :smile:

The Gradle version configured in distributionUrl properties doesn’t matter for me; it just needs the right Java version. I use the newest Gradle version 8.7, and it is compatible with Java 11 when you check via gradlew -v. The matrix is maybe a good starting point to check gradle and java compatibility, but for running the tests, it doesnt matter for me.

If you use homebrew, you can manage java versions like this:

brew install openjdk     # installs version 21
brew install openjdk@11  # version 11

java -version   # openjdk version "21.0.2" 2024-01-16

brew unlink openjdk
brew link openjdk@11

java -version   # openjdk version "11.0.22" 2024-01-16

# restore version 21
brew unlink openjdk@11
brew link openjdk

ls -l $HOMEBREW_PREFIX/bin/java
1 Like