Java - Gradle detecting JDK version

less than 1 minute read

We can control gradle auto detecting JDK and auto download options as shown in below.

1
2
3
org.gradle.java.installations.auto-detect=false
org.gradle.java.installations.auto-download=false
org.gradle.java.installations.fromEnv=ENV_VALUE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
java {
  toolChain {
    languageVersion = JavaLanguageVersion.of(19)
  }
}

dependencies {
  testImplementation libs.junit.platform
}

tasks.withType(Test).configureEach {
  useJUnitPlatform()
  jvmArgs['--enable-preview']
}

tasks.withType(JavaCompile).configureEach {
  useJUnitPlatform()
  options.compileArgs.add('--enable--preview')
}

Categories:

Updated: