Fix Dockerfile task up-to-date logic
MODIFY
src/functTest/groovy/com/bmuschko/gradle/docker/tasks/image/DockerfileFunctionalTest.groovy
src/functTest/groovy/com/bmuschko/gradle/docker/tasks/image/DockerfileFunctionalTest.groovy
@@ -4,6 +4,7 @@ import com.bmuschko.gradle.docker.AbstractFunctionalTest
import com.bmuschko.gradle.docker.TestConfiguration
import org.gradle.api.GradleException
import org.gradle.testkit.runner.BuildResult
+import org.gradle.testkit.runner.TaskOutcome
import java.nio.file.Files
import java.nio.file.Paths
@@ -194,4 +195,36 @@ task ${DOCKERFILE_TASK_NAME}(type: Dockerfile) {
MAINTAINER Benjamin Muschko "benjamin.muschko@gmail.com
"""
}
+
+ def "Dockerfile task can be up-to-date"() {
+ given:
+ buildFile << """
+import com.bmuschko.gradle.docker.tasks.image.Dockerfile
+
+ext.version = project.properties.getOrDefault('version', '1.0')
+
+task ${DOCKERFILE_TASK_NAME}(type: Dockerfile) {
+ instruction 'FROM $TEST_IMAGE_WITH_TAG'
+ instruction { 'MAINTAINER Benjamin Muschko "benjamin.muschko@gmail.com"' }
+ label([ver: version])
+}
+"""
+ when:
+ def result = build(DOCKERFILE_TASK_NAME)
+
+ then:
+ TaskOutcome.SUCCESS == result.tasks.first().outcome
+
+ when:
+ result = build(DOCKERFILE_TASK_NAME)
+
+ then:
+ TaskOutcome.UP_TO_DATE == result.tasks.first().outcome
+
+ when:
+ result = build(DOCKERFILE_TASK_NAME, "-Pversion=1.1")
+
+ then:
+ TaskOutcome.SUCCESS == result.tasks.first().outcome
+ }
}

MODIFY
src/main/groovy/com/bmuschko/gradle/docker/tasks/image/Dockerfile.groovy
src/main/groovy/com/bmuschko/gradle/docker/tasks/image/Dockerfile.groovy
@@ -28,7 +28,7 @@ class Dockerfile extends DefaultTask {
File destFile = project.file("$project.buildDir/docker/Dockerfile")
Dockerfile() {
-
+ inputs.property("instructionsCache", { instructions.collect { it.build() }.join('\n') })
}
@TaskAction

Fix Dockerfile task up-to-date logic (#433)