Java library build fails to compile, but works in IntelliJ

I’m running into a weird problem when I try to build my project via Gradle.

The build works fine when I import the project into IntelliJ and build/run tests via the IDE. However, if I run ./gradlew test, the build fails and it’s unable to resolve symbols in the JDK (like GenericArrayType).

If I delegate IntelliJ’s build/run actions to Gradle, I see the same problems in my IDE as well, so something seems to be up with my Gradle build, and I can’t figure out what. Other projects work fine, so it seems to be a problem with this specific project.

I have tried this on diffrent machines (one running Ubuntu and the other running macOS) and the problem persists. Can someone help me figure out what’s going wrong here?