From adad764f8d8e458fc6db79caebd08fc06d6b8e3b Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Sat, 23 Mar 2024 19:57:57 +0100 Subject: [PATCH] Fix deprecations in Gradle 8.7 --- build.xml | 3 +++ .../forbiddenapis/gradle/ForbiddenApisPlugin.groovy | 7 +++++-- src/test/gradle/build.gradle | 11 ++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/build.xml b/build.xml index 9228d17..cec038a 100644 --- a/build.xml +++ b/build.xml @@ -111,6 +111,9 @@ + + + diff --git a/src/main/groovy/de/thetaphi/forbiddenapis/gradle/ForbiddenApisPlugin.groovy b/src/main/groovy/de/thetaphi/forbiddenapis/gradle/ForbiddenApisPlugin.groovy index abc8185..9192406 100644 --- a/src/main/groovy/de/thetaphi/forbiddenapis/gradle/ForbiddenApisPlugin.groovy +++ b/src/main/groovy/de/thetaphi/forbiddenapis/gradle/ForbiddenApisPlugin.groovy @@ -46,9 +46,12 @@ public class ForbiddenApisPlugin extends ForbiddenApisPluginBase { group = JavaBasePlugin.VERIFICATION_GROUP; } + // retrieve Java Extension, if it is not available fallback to project convention: + def javaExtension = project.extensions.findByName('java') ?: project + // 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 }; + Closure targetCompatibilityGetter = { (javaExtension.targetCompatibility?.hasProperty('java11Compatible') && javaExtension.targetCompatibility?.java11Compatible) ? + javaExtension.targetCompatibility.toString() : javaExtension.targetCompatibility?.majorVersion }; // Define our tasks (one for each SourceSet): project.sourceSets.all{ sourceSet -> diff --git a/src/test/gradle/build.gradle b/src/test/gradle/build.gradle index 75e09bc..71c0c0a 100644 --- a/src/test/gradle/build.gradle +++ b/src/test/gradle/build.gradle @@ -29,7 +29,16 @@ buildscript { apply plugin: 'java' apply plugin: 'de.thetaphi.forbiddenapis' -sourceCompatibility = forbiddenSourceCompatibility +if (project.extensions.findByName('java')) { + + java { + sourceCompatibility = JavaVersion.toVersion(forbiddenSourceCompatibility) + } + +} else { + // TODO: Remove this after Gradle 4.10 + sourceCompatibility = JavaVersion.toVersion(forbiddenSourceCompatibility) +} sourceSets { main {