diff --git a/gradle-license-plugin/src/main/kotlin/com/jaredsburrows/license/LicenseReportTask.kt b/gradle-license-plugin/src/main/kotlin/com/jaredsburrows/license/LicenseReportTask.kt index 811b0829..4275a334 100644 --- a/gradle-license-plugin/src/main/kotlin/com/jaredsburrows/license/LicenseReportTask.kt +++ b/gradle-license-plugin/src/main/kotlin/com/jaredsburrows/license/LicenseReportTask.kt @@ -16,6 +16,7 @@ import org.gradle.api.artifacts.ResolvedArtifact import org.gradle.api.artifacts.ResolvedDependency import org.gradle.api.artifacts.dsl.DependencyHandler import org.gradle.api.tasks.Input +import org.gradle.api.tasks.InputFile import org.gradle.api.tasks.Optional import org.gradle.api.tasks.TaskAction import java.io.File @@ -30,6 +31,10 @@ internal open class LicenseReportTask : BaseLicenseReportTask() { // tasks can't @Input var assetDirs = emptyList() @Optional @Input var variantName: String? = null + // This input is used by the task indirectly via some project properties (such as "configurations" and "dependencies") + // that affect the task's outcome. When the mentioned project properties change the task should re-run the next time + // it is requested and should *not* be marked as UP-TO-DATE. + @InputFile var buildFile: File? = null private val projects = mutableListOf() private var pomConfiguration = "poms" diff --git a/gradle-license-plugin/src/main/kotlin/com/jaredsburrows/license/projectAndroid.kt b/gradle-license-plugin/src/main/kotlin/com/jaredsburrows/license/projectAndroid.kt index 7c1d0cdb..91fd9905 100644 --- a/gradle-license-plugin/src/main/kotlin/com/jaredsburrows/license/projectAndroid.kt +++ b/gradle-license-plugin/src/main/kotlin/com/jaredsburrows/license/projectAndroid.kt @@ -96,6 +96,7 @@ private fun Project.configureVariant( .srcDirs .toList() it.variantName = variant.name + it.buildFile = buildFile } } } diff --git a/gradle-license-plugin/src/main/kotlin/com/jaredsburrows/license/projectJava.kt b/gradle-license-plugin/src/main/kotlin/com/jaredsburrows/license/projectJava.kt index e8c9807f..48f90149 100644 --- a/gradle-license-plugin/src/main/kotlin/com/jaredsburrows/license/projectJava.kt +++ b/gradle-license-plugin/src/main/kotlin/com/jaredsburrows/license/projectJava.kt @@ -18,5 +18,7 @@ internal fun Project.isJavaProject(): Boolean { * All of these plugins will apply the JavaPlugin(relies on JavaBasePlugin) or JavaPlatformPlugin. */ internal fun Project.configureJavaProject() { - tasks.register("licenseReport", LicenseReportTask::class.java) + tasks.register("licenseReport", LicenseReportTask::class.java) { + it.buildFile = buildFile + } } diff --git a/gradle-license-plugin/src/test/groovy/com/jaredsburrows/license/LicensePluginAndroidSpec.groovy b/gradle-license-plugin/src/test/groovy/com/jaredsburrows/license/LicensePluginAndroidSpec.groovy index c9d25691..76f730a9 100644 --- a/gradle-license-plugin/src/test/groovy/com/jaredsburrows/license/LicensePluginAndroidSpec.groovy +++ b/gradle-license-plugin/src/test/groovy/com/jaredsburrows/license/LicensePluginAndroidSpec.groovy @@ -234,6 +234,81 @@ final class LicensePluginAndroidSpec extends Specification { taskName << ['licenseDebugReport', 'licenseReleaseReport'] } + @Unroll def 'not UP-TO-DATE when dependencies change'() { + given: + def originalBuildFile = """ + buildscript { + dependencies { + classpath files($classpathString) + } + } + + repositories { + maven { + url '${mavenRepoUrl}' + } + } + + apply plugin: 'com.android.application' + apply plugin: 'com.jaredsburrows.license' + + android { + compileSdkVersion $compileSdkVersion + + defaultConfig { + applicationId 'com.example' + } + } + + dependencies { + implementation 'com.android.support:appcompat-v7:26.1.0' + } + """ + def modifiedBuildFile = """ + buildscript { + dependencies { + classpath files($classpathString) + } + } + + repositories { + maven { + url '${mavenRepoUrl}' + } + } + + apply plugin: 'com.android.application' + apply plugin: 'com.jaredsburrows.license' + + android { + compileSdkVersion $compileSdkVersion + + defaultConfig { + applicationId 'com.example' + } + } + + dependencies { + implementation 'com.android.support:appcompat-v7:26.1.0' + // This is a new dependency + implementation 'com.android.support:design:26.1.0' + } + """ + + when: + buildFile << originalBuildFile + def result1 = gradleWithCommand(testProjectDir.root, "${taskName}", '-s') + buildFile << modifiedBuildFile + def result2 = gradleWithCommand(testProjectDir.root, "${taskName}", '-s') + + then: + result1.task(":${taskName}").outcome == SUCCESS + result2.task(":${taskName}").outcome == SUCCESS + + where: + taskName << ['licenseDebugReport', 'licenseReleaseReport'] + } + @Unroll def '#taskName with buildTypes'() { given: buildFile <<