Skip to content

Commit

Permalink
Also get sourceSets from java extension, if available
Browse files Browse the repository at this point in the history
  • Loading branch information
uschindler committed Mar 23, 2024
1 parent 228248c commit 068b0ca
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 068b0ca

Please sign in to comment.