From 068b0ca72b4bdc5054467e8f1b5a36c8b98694bf Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Sat, 23 Mar 2024 23:23:50 +0100 Subject: [PATCH] Also get sourceSets from java extension, if available --- .../thetaphi/forbiddenapis/gradle/ForbiddenApisPlugin.groovy | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/groovy/de/thetaphi/forbiddenapis/gradle/ForbiddenApisPlugin.groovy b/src/main/groovy/de/thetaphi/forbiddenapis/gradle/ForbiddenApisPlugin.groovy index 9192406..a251821 100644 --- a/src/main/groovy/de/thetaphi/forbiddenapis/gradle/ForbiddenApisPlugin.groovy +++ b/src/main/groovy/de/thetaphi/forbiddenapis/gradle/ForbiddenApisPlugin.groovy @@ -46,15 +46,16 @@ public class ForbiddenApisPlugin extends ForbiddenApisPluginBase { group = JavaBasePlugin.VERIFICATION_GROUP; } - // retrieve Java Extension, if it is not available fallback to project convention: + // retrieve Java Extension and sourceSets; if not available, fallback to project convention: def javaExtension = project.extensions.findByName('java') ?: project + def sourceSets = javaExtension.hasProperty('sourceSets') ? javaExtension.sourceSets : project.sourceSets // 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 = { (javaExtension.targetCompatibility?.hasProperty('java11Compatible') && javaExtension.targetCompatibility?.java11Compatible) ? javaExtension.targetCompatibility.toString() : javaExtension.targetCompatibility?.majorVersion }; // Define our tasks (one for each SourceSet): - project.sourceSets.all{ sourceSet -> + sourceSets.all{ sourceSet -> String sourceSetTaskName = sourceSet.getTaskName(FORBIDDEN_APIS_TASK_NAME, null); def sourceSetTask = TASK_AVOIDANCE_AVAILABLE ? project.tasks.register(sourceSetTaskName, CheckForbiddenApis.class) : project.tasks.create(sourceSetTaskName, CheckForbiddenApis.class);