From a70cb0eec0ba6c2be4cc7c325a4b37c479576489 Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Wed, 23 Mar 2022 19:25:19 +0100 Subject: [PATCH] Workaround for #179 --- .../de/thetaphi/forbiddenapis/gradle/plugin-init.groovy | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/resources/de/thetaphi/forbiddenapis/gradle/plugin-init.groovy b/src/main/resources/de/thetaphi/forbiddenapis/gradle/plugin-init.groovy index 6875b05..37079b6 100644 --- a/src/main/resources/de/thetaphi/forbiddenapis/gradle/plugin-init.groovy +++ b/src/main/resources/de/thetaphi/forbiddenapis/gradle/plugin-init.groovy @@ -30,6 +30,10 @@ forbiddenTask.configure { group = JavaBasePlugin.VERIFICATION_GROUP; } +// Gradle is buggy with it's JavaVersion enum: We use majorVersion property before Java 11 (6,7,8,9,10) and for later we use toString() to be future-proof: +Closure targetCompatibilityGetter = { (project.targetCompatibility?.hasProperty('java11Compatible') && project.targetCompatibility?.java11Compatible) ? + project.targetCompatibility.toString() : project.targetCompatibility?.majorVersion }; + // Define our tasks (one for each SourceSet): project.sourceSets.all{ sourceSet -> String sourceSetTaskName = sourceSet.getTaskName(FORBIDDEN_APIS_TASK_NAME, null); @@ -45,9 +49,7 @@ project.sourceSets.all{ sourceSet -> } classesDirs = { sourceSet.output.hasProperty('classesDirs') ? sourceSet.output.classesDirs : project.files(sourceSet.output.classesDir) } classpath = { sourceSet.compileClasspath } - // Gradle is buggy with it's JavaVersion enum: We use majorVersion property before Java 11 (6,7,8,9,10) and for later we use toString() to be future-proof: - targetCompatibility = { (project.targetCompatibility?.hasProperty('java11Compatible') && project.targetCompatibility?.java11Compatible) ? - project.targetCompatibility.toString() : project.targetCompatibility?.majorVersion } + targetCompatibility = targetCompatibilityGetter } } forbiddenTask.configure {