Skip to main content

Gradle Cheatsheet

Upgrade gradle wrapper version

# Using existing gradle wrapper
./gradlew wrapper --gradle-version latest
# Or use the global gradle binary
gradle wrapper --gradle-version 8.5 --distribution-type al

Enable Java Preview Features

To use preview features such as Java 21 String Templates, you need to enable the preview feature in gradle

tasks.withType(JavaCompile).configureEach {
options.compilerArgs += "--enable-preview"

tasks.withType(Test).configureEach {
jvmArgs += "--enable-preview"

tasks.withType(JavaExec).configureEach {
jvmArgs += "--enable-preview"

Invalid source release when using Intellij

When using intellij after upgrading project JDK and settings, you may still see Cause: error: invalid source release: 17, Cause: error: invalid source release: 21 etc. You need to update the JVM used by gradle as well under Settings -> Build, Execution, Deployment -> Build Tools -> Gradle -> Gradle JVM.