From 3b91ef79942243f736caa0a4f5c8786fcc068828 Mon Sep 17 00:00:00 2001 From: Nelson Osacky Date: Thu, 31 Jan 2019 00:47:02 +0100 Subject: [PATCH] Use Relative Sensitivity for GenerateProtoTask, use name only sensitivity for classpath. (#293) Using absolute sensitivity does not allow this task output to be re-used across different machines. Classpath jars and files can be located in different parts of the filesystem relative to the current working directory so the task output is not cacheable unless we use NAME_ONLY sensitivity. --- .../com/google/protobuf/gradle/GenerateProtoTask.groovy | 6 +++--- .../com/google/protobuf/gradle/ProtobufPlugin.groovy | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy b/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy index a1dc6fca..7e6bce10 100644 --- a/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy @@ -31,7 +31,6 @@ package com.google.protobuf.gradle import com.google.common.base.Preconditions import com.google.common.collect.ImmutableList - import org.gradle.api.DefaultTask import org.gradle.api.GradleException import org.gradle.api.Named @@ -43,6 +42,7 @@ import org.gradle.api.internal.file.DefaultSourceDirectorySet import org.gradle.api.internal.file.FileResolver import org.gradle.api.internal.file.collections.DefaultDirectoryFileTreeFactory import org.gradle.api.logging.LogLevel +import org.gradle.api.tasks.PathSensitivity import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.TaskAction import org.gradle.util.ConfigureUtil @@ -336,7 +336,7 @@ public class GenerateProtoTask extends DefaultTask { includeDirs.add(dir) // Register all files under the directory as input so that Gradle will check their changes for // incremental build - inputs.dir(dir) + inputs.dir(dir).withPathSensitivity(PathSensitivity.RELATIVE) } /** @@ -346,7 +346,7 @@ public class GenerateProtoTask extends DefaultTask { checkCanConfig() sourceFiles.from(files) // Register the files as input so that Gradle will check their changes for incremental build - inputs.files(files) + inputs.files(files).withPathSensitivity(PathSensitivity.RELATIVE) } /** diff --git a/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy b/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy index a7448565..2e6a5c74 100644 --- a/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy @@ -30,7 +30,6 @@ package com.google.protobuf.gradle import com.google.common.collect.ImmutableList - import org.gradle.api.Action import org.gradle.api.GradleException import org.gradle.api.Plugin @@ -44,6 +43,7 @@ import org.gradle.api.internal.file.FileResolver import org.gradle.api.internal.file.collections.DefaultDirectoryFileTreeFactory import org.gradle.api.logging.LogLevel import org.gradle.api.plugins.AppliedPlugin +import org.gradle.api.tasks.PathSensitivity import org.gradle.api.tasks.SourceSet import javax.inject.Inject @@ -342,7 +342,8 @@ class ProtobufPlugin implements Plugin { task = project.tasks.create(extractProtosTaskName, ProtobufExtract) { description = "Extracts proto files/dependencies specified by 'protobuf' configuration" destDir = getExtractedProtosDir(sourceSetName) as File - inputs.files project.configurations[Utils.getConfigName(sourceSetName, 'protobuf')] + inputs.files(project.configurations[Utils.getConfigName(sourceSetName, 'protobuf')]) + .withPathSensitivity(PathSensitivity.NAME_ONLY) isTest = Utils.isTest(sourceSetName) } } @@ -372,6 +373,7 @@ class ProtobufPlugin implements Plugin { destDir = getExtractedIncludeProtosDir(sourceSetOrVariantName) as File inputs.files (compileClasspathConfiguration ?: project.configurations[Utils.getConfigName(sourceSetOrVariantName, 'compile')]) + .withPathSensitivity(PathSensitivity.NAME_ONLY) // TL; DR: Make protos in 'test' sourceSet able to import protos from the 'main' // sourceSet. Sub-configurations, e.g., 'testCompile' that extends 'compile', don't @@ -392,7 +394,8 @@ class ProtobufPlugin implements Plugin { // 'resources' of the output of 'main', in which the source protos are placed. This is // nicer than the ad-hoc solution that Android has, because it works for any extended // configuration, not just 'testCompile'. - inputs.files getSourceSets()[sourceSetOrVariantName].compileClasspath + inputs.files (getSourceSets()[sourceSetOrVariantName].compileClasspath) + .withPathSensitivity(PathSensitivity.NAME_ONLY) } isTest = Utils.isTest(sourceSetOrVariantName) }