Gradle 8.5/Java 21 reporting Unsupported class file major version 65

I am getting a class version error when compiling my groovy test code. I am using Gradle 8.5 and Java 21 which I believe is a supported combination. Any tips why this still fails?

* What went wrong:
Execution failed for task ':compileTestGroovy'.
> BUG! exception in phase 'semantic analysis' in source unit '/gee/workspace/..../MyControllerSpec.groovy' Unsupported class file major version 65
$ ./gradlew -v

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 (Oracle Corporation 21+35-LTS-2513)
OS:           Linux 5.4.17-2136.325.5.1.el7uek.x86_64 amd64

As it is the Groovy compilation that is failing, I guess you are using a Groovy version that is not Java 21 compatible

Isn’t it using the groovy in gradle?

Why should it?
Unless you tell it to.
The Groovy version you use to build production code (or in your case test code) has nothing to do with the Groovy version used for Groovy DSL build scripts or plugins written in Groovy.
Those are two totally separate things unless you configure it like that for example when building build logic by using localGroovy() instead of a normal Groovy dependency.

So I guess up to this point, my cucumberTest just used the groovy plugin. From what you are saying I need to setup a different groovy not that works with Java 21. I haven’t been able to find a reference yet for how to have compileTestGroovy to use a different groovy.

Just having the Groovy plugin will not bring you any Groovy version.
You might have an explicit dependency or you might have an implicit dependency, but it is coming from a dependency.
You can use the dependencies task, or the dependencyInsight task, or if you can a build --scan to see where it comes from and which version it is.