diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImage.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImage.java index 023d4a6c50..6480432029 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImage.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImage.java @@ -68,6 +68,8 @@ public abstract class BootBuildImage extends DefaultTask { private static final String BUILDPACK_JVM_VERSION_KEY = "BP_JVM_VERSION"; + private final Property pullPolicy; + private final String projectName; private final CacheSpec buildCache; @@ -94,6 +96,7 @@ public abstract class BootBuildImage extends DefaultTask { this.buildCache = getProject().getObjects().newInstance(CacheSpec.class); this.launchCache = getProject().getObjects().newInstance(CacheSpec.class); this.docker = getProject().getObjects().newInstance(DockerSpec.class); + this.pullPolicy = getProject().getObjects().property(PullPolicy.class); } /** @@ -175,7 +178,17 @@ public abstract class BootBuildImage extends DefaultTask { @Input @Optional @Option(option = "pullPolicy", description = "The image pull policy") - public abstract Property getPullPolicy(); + public Property getPullPolicy() { + return this.pullPolicy; + } + + /** + * Sets image pull policy that will be used when building the image. + * @param pullPolicy the pull policy to use + */ + public void setPullPolicy(String pullPolicy) { + getPullPolicy().set(PullPolicy.valueOf(pullPolicy)); + } /** * Whether the built image should be pushed to a registry. @@ -342,7 +355,7 @@ public abstract class BootBuildImage extends DefaultTask { } private BuildRequest customizePullPolicy(BuildRequest request) { - PullPolicy pullPolicy = getPullPolicy().map(PullPolicy::valueOf).getOrNull(); + PullPolicy pullPolicy = getPullPolicy().getOrNull(); if (pullPolicy != null) { request = request.withPullPolicy(pullPolicy); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageTests.java index fdd7226fec..058e62957f 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageTests.java @@ -216,7 +216,7 @@ class BootBuildImageTests { @Test void whenPullPolicyIsConfiguredThenRequestHasPullPolicy() { - this.buildImage.getPullPolicy().set(PullPolicy.NEVER.toString()); + this.buildImage.getPullPolicy().set(PullPolicy.NEVER); assertThat(this.buildImage.createRequest().getPullPolicy()).isEqualTo(PullPolicy.NEVER); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests-buildsImageWithPullPolicy.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests-buildsImageWithPullPolicy.gradle index cf75779cbb..7330c2b701 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests-buildsImageWithPullPolicy.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests-buildsImageWithPullPolicy.gradle @@ -1,3 +1,5 @@ +import org.springframework.boot.buildpack.platform.build.PullPolicy; + plugins { id 'java' id 'org.springframework.boot' version '{version}' @@ -12,4 +14,5 @@ targetCompatibility = '1.8' bootBuildImage { builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1" + pullPolicy = PullPolicy.ALWAYS }