Skip to content

Commit 46177a5

Browse files
committed
Fix initialization problem caused by #162 with project.afterEvaluate() which was way too clever. Just always depend on sourceSet's output unconditionally.
1 parent 261ff53 commit 46177a5

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

src/main/resources/de/thetaphi/forbiddenapis/gradle/plugin-init.groovy

+4-11
Original file line numberDiff line numberDiff line change
@@ -44,30 +44,23 @@ forbiddenTask.configure {
4444

4545
// Define our tasks (one for each SourceSet):
4646
project.sourceSets.all{ sourceSet ->
47-
def getSourceSetClassesDirs = { sourceSet.output.hasProperty('classesDirs') ? sourceSet.output.classesDirs : project.files(sourceSet.output.classesDir) }
4847
String sourceSetTaskName = sourceSet.getTaskName(FORBIDDEN_APIS_TASK_NAME, null);
4948
def sourceSetTask = TASK_AVOIDANCE_AVAILABLE ? project.tasks.register(sourceSetTaskName, CheckForbiddenApis.class) :
5049
project.tasks.create(sourceSetTaskName, CheckForbiddenApis.class);
51-
sourceSetTask.configure { task ->
50+
sourceSetTask.configure {
5251
description = "Runs forbidden-apis checks on '${sourceSet.name}' classes.";
52+
dependsOn(sourceSet.output);
53+
outputs.upToDateWhen { true }
5354
conventionMapping.with{
5455
extensionProps.each{ key ->
5556
map(key, { extension[key] });
5657
}
57-
classesDirs = { getSourceSetClassesDirs() }
58+
classesDirs = { sourceSet.output.hasProperty('classesDirs') ? sourceSet.output.classesDirs : project.files(sourceSet.output.classesDir) }
5859
classpath = { sourceSet.compileClasspath }
5960
// 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:
6061
targetCompatibility = { (project.targetCompatibility?.hasProperty('java11Compatible') && project.targetCompatibility?.java11Compatible) ?
6162
project.targetCompatibility.toString() : project.targetCompatibility?.majorVersion }
6263
}
63-
// add dependency to compile task after evaluation, if the classesDirs collection has overlaps with our SourceSet:
64-
project.afterEvaluate{
65-
def sourceSetDirs = getSourceSetClassesDirs().files;
66-
if (classesDirs.any{ sourceSetDirs.contains(it) }) {
67-
task.dependsOn(sourceSet.output);
68-
}
69-
}
70-
outputs.upToDateWhen { true }
7164
}
7265
forbiddenTask.configure {
7366
dependsOn(sourceSetTask)

0 commit comments

Comments
 (0)