From 1bb80c929c8d2f86b8c8f45a43d6edb6ddbdcd96 Mon Sep 17 00:00:00 2001 From: soloturn Date: Thu, 10 Feb 2022 17:10:52 +0100 Subject: [PATCH] gradle, permit 'gradle test' with java8 --- build.gradle.kts | 14 ++++++++++++-- gradle.properties | 1 - 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 5dcc9466d..37d2f291b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,10 @@ -val javacRelease: String by project +// permits to start the build setting the javac release parameter, no parameter means build for java8: +// gradle clean build -x javaDoc -PjavacRelease=8 +// gradle clean build -x javaDoc -PjavacRelease=17 +// also supported is to build first, with java17, then switch the java version, and run the test with java8: +// gradle clean build -x javaDoc -x test +// gradle test +val javacRelease = (project.findProperty("javacRelease") ?: "8") as String plugins { java @@ -52,7 +58,11 @@ sourceSets { } tasks.compileJava { - options.release.set(Integer.parseInt(javacRelease)) + if (JavaVersion.current().isJava8) { + java.targetCompatibility = JavaVersion.VERSION_1_8 + } else { + options.release.set(Integer.parseInt(javacRelease)) + } } tasks.withType { diff --git a/gradle.properties b/gradle.properties index 585006db2..92dd41656 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1 @@ -javacRelease = 8 version = 1.2022.1-SNAPSHOT