Skip to content

Commit

Permalink
Fix bug on adding dependencies. This closes #131
Browse files Browse the repository at this point in the history
  • Loading branch information
uschindler committed Oct 3, 2017
1 parent cca2274 commit 643ac0d
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,21 @@ def extensionProps = CheckForbiddenApisExtension.class.declaredFields.findAll{ f

// Define our tasks (one for each SourceSet):
def forbiddenTasks = project.sourceSets.collect{ sourceSet ->
def getClassesDirs = { sourceSet.output.hasProperty('classesDirs') ? sourceSet.output.classesDirs : project.files(sourceSet.output.classesDir) }
def getSourceSetClassesDirs = { sourceSet.output.hasProperty('classesDirs') ? sourceSet.output.classesDirs : project.files(sourceSet.output.classesDir) }
project.tasks.create(sourceSet.getTaskName(FORBIDDEN_APIS_TASK_NAME, null), CheckForbiddenApis.class) {
description = "Runs forbidden-apis checks on '${sourceSet.name}' classes.";
conventionMapping.with{
extensionProps.each{ key ->
map(key, { extension[key] });
}
classesDirs = { getClassesDirs() }
classesDirs = { getSourceSetClassesDirs() }
classpath = { sourceSet.compileClasspath }
targetCompatibility = { project.targetCompatibility?.toString() }
}
// add dependency to compile task after evaluation, if the classesDirs collection has overlaps with our SourceSet:
project.afterEvaluate{
if (!classesDirs.minus(getClassesDirs()).isEmpty()) {
project.afterEvaluate{
def sourceSetDirs = getSourceSetClassesDirs().files;
if (classesDirs.any{ sourceSetDirs.contains(it) }) {
dependsOn(sourceSet.output);
}
}
Expand Down

0 comments on commit 643ac0d

Please sign in to comment.