diff --git a/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy b/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy index b51e6d6f..e0dee341 100644 --- a/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/GenerateProtoTask.groovy @@ -29,6 +29,8 @@ */ package com.google.protobuf.gradle +import org.gradle.api.tasks.InputFile + import static java.nio.charset.StandardCharsets.US_ASCII import com.google.common.base.Preconditions @@ -330,8 +332,38 @@ public abstract class GenerateProtoTask extends DefaultTask { @Internal("Input captured by getAlternativePaths(), this is used to query alternative path by locator name.") abstract MapProperty getLocatorToAlternativePathsMapping() - @InputFiles - @PathSensitive(PathSensitivity.NONE) + @Input + @Optional + Provider getProtocArtifact() { + // Ideally, this value could be mapped from the protocLocator property, but Provider#map cannot return null in + // Gradle < 6.2. See https://github.com/gradle/gradle/issues/11979 + return providerFactory.provider { + def protocArtifact = protocLocator.get().artifact + if (protocArtifact) { + def (groupId, artifact, version) = ToolsLocator.artifactParts(protocArtifact) + outputs.doNotCacheIf("protoc is a SNAPSHOT version", { + version.endsWith("-SNAPSHOT") + }) + "$groupId:$artifact:$version".toString() + } else { + null + } + } + } + + @InputFile + @PathSensitive(PathSensitivity.ABSOLUTE) + @Optional + Provider getProtocPath() { + // Ideally, this value could be mapped from the protocLocator property, but Provider#map cannot return null in + // Gradle < 6.2. See https://github.com/gradle/gradle/issues/11979 + return providerFactory.provider { + def path = getProtocLocator().get().path + path ? new File(path) : null + } + } + + @Internal ConfigurableFileCollection getAlternativePaths() { return objectFactory.fileCollection().from(getLocatorToAlternativePathsMapping().get().values()) }