Created
December 4, 2023 12:17
-
-
Save ClausPolanka/bce060a78a8027a4c3022213fe11fcad to your computer and use it in GitHub Desktop.
Gradle custom tasks to compile with different Java versions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins { | |
id("java") | |
} | |
tasks.register("compileOn11", JavaCompile::class.java) { | |
javaCompiler = javaToolchains.compilerFor { | |
languageVersion = JavaLanguageVersion.of(11) | |
} | |
source = sourceSets["main"].allSource.asFileTree | |
classpath = sourceSets["main"].compileClasspath | |
destinationDirectory.set(file("build/classes/java/main/11")) | |
} | |
tasks.register("compileOn17", JavaCompile::class.java) { | |
javaCompiler = javaToolchains.compilerFor { | |
languageVersion = JavaLanguageVersion.of(17) | |
} | |
source = sourceSets["main"].allSource.asFileTree | |
classpath = sourceSets["main"].compileClasspath | |
destinationDirectory.set(file("build/classes/java/main/17")) | |
} | |
tasks.register("compileOn21", JavaCompile::class.java) { | |
javaCompiler = javaToolchains.compilerFor { | |
languageVersion = JavaLanguageVersion.of(21) | |
} | |
source = sourceSets["main"].allSource.asFileTree | |
classpath = sourceSets["main"].compileClasspath | |
destinationDirectory.set(file("build/classes/java/main/21")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment