Java 21 issue with test fixtures plugin


I’m currently migrating a Spring boot based java application to java 21 and gradle 8.5. I’ve been able to use java 21 in runtime with a docker, and my build process ends well but if I try to use test fixtures in my build, it breaks with the following error.

 Task :library:potato:compileTestFixturesGroovy FAILED

* What went wrong:
Execution failed for task ':library:potato:compileTestFixturesGroovy'.
> BUG! exception in phase 'semantic analysis' in source unit '/Users/tomato/code/gh/project/library/potato/src/testFixtures/groovy/com/potato/PotatoDataFactory.groovy' Unsupported class file major version 65

My project structure is composed of a main service that bundles some libraries from the same build, and those libraries often expose fixtures to help us proving test data for internal use. Those are direct project dependencies.

Gradle 8.5

Build time:   2023-11-29 14:08:57 UTC
Revision:     28aca86a7180baa17117e0e5ba01d8ea9feca598

Kotlin:       1.9.20
Groovy:       3.0.17
Ant:          Apache Ant(TM) version 1.10.13 compiled on January 4 2023
JVM:          21.0.2 (Azul Systems, Inc. 21.0.2+13-LTS)
OS:           Mac OS X 14.3 aarch64

It seems to me that it is possible that the java-test-fixtures plugin might not be reading properly the java toolchain configuration that I’m using to specify the language version

    java {
        toolchain {
            languageVersion = JavaLanguageVersion.of(21)

Can you help me? , thanks in advance.

You are probably using a Groovy version that is not Java 21 compatible

I though that but I’m using this in my code, should I add something else?

build.gradle (library potato)
testFixturesImplementation libs.groovy


Are you sure 4.0.4 is Java 21 compatible?
Try with 4.0.18.

It seems that indeed that was the issue, after upgrading to 4.0.18 fixtures are working fine.

Thank you

1 Like