From de9289ca6f9a5fdc5fc575e0226fbdb4e4d83c31 Mon Sep 17 00:00:00 2001 From: Juuxel <6596629+Juuxel@users.noreply.github.com> Date: Mon, 22 Nov 2021 12:11:15 +0200 Subject: Use java toolchains --- build.gradle | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'build.gradle') diff --git a/build.gradle b/build.gradle index 39c5940..5f2f9de 100644 --- a/build.gradle +++ b/build.gradle @@ -5,9 +5,6 @@ plugins { id 'checkstyle' } -sourceCompatibility = JavaVersion.VERSION_17 -targetCompatibility = JavaVersion.VERSION_17 - if(rootProject.file('private.gradle').exists()) { //Publishing details apply from: 'private.gradle' } @@ -61,6 +58,22 @@ java { withJavadocJar() } +allprojects { + plugins.withId('java') { // when the java plugin is applied in the project + java { + // Use Java 17 toolchain if running on older version of Java, but allow newer versions + if (!JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) { + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } + } else { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + } + } +} + tasks.withType(JavaCompile) { // ensure that the encoding is set to UTF-8, no matter what the system default is // this fixes some edge cases with special characters not displaying correctly -- cgit