Skip to content

Commit b78b22b

Browse files
Allow Gradle task property to be set with String or enum value
See gh-32769
1 parent c53c8c8 commit b78b22b

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImage.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public abstract class BootBuildImage extends DefaultTask {
6868

6969
private static final String BUILDPACK_JVM_VERSION_KEY = "BP_JVM_VERSION";
7070

71+
private final Property<PullPolicy> pullPolicy;
72+
7173
private final String projectName;
7274

7375
private final CacheSpec buildCache;
@@ -94,6 +96,7 @@ public BootBuildImage() {
9496
this.buildCache = getProject().getObjects().newInstance(CacheSpec.class);
9597
this.launchCache = getProject().getObjects().newInstance(CacheSpec.class);
9698
this.docker = getProject().getObjects().newInstance(DockerSpec.class);
99+
this.pullPolicy = getProject().getObjects().property(PullPolicy.class);
97100
}
98101

99102
/**
@@ -175,7 +178,17 @@ public BootBuildImage() {
175178
@Input
176179
@Optional
177180
@Option(option = "pullPolicy", description = "The image pull policy")
178-
public abstract Property<String> getPullPolicy();
181+
public Property<PullPolicy> getPullPolicy() {
182+
return this.pullPolicy;
183+
}
184+
185+
/**
186+
* Sets image pull policy that will be used when building the image.
187+
* @param pullPolicy the pull policy to use
188+
*/
189+
public void setPullPolicy(String pullPolicy) {
190+
getPullPolicy().set(PullPolicy.valueOf(pullPolicy));
191+
}
179192

180193
/**
181194
* Whether the built image should be pushed to a registry.
@@ -342,7 +355,7 @@ private BuildRequest customizeCreator(BuildRequest request) {
342355
}
343356

344357
private BuildRequest customizePullPolicy(BuildRequest request) {
345-
PullPolicy pullPolicy = getPullPolicy().map(PullPolicy::valueOf).getOrNull();
358+
PullPolicy pullPolicy = getPullPolicy().getOrNull();
346359
if (pullPolicy != null) {
347360
request = request.withPullPolicy(pullPolicy);
348361
}

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ void whenUsingDefaultConfigurationThenRequestHasAlwaysPullPolicy() {
216216

217217
@Test
218218
void whenPullPolicyIsConfiguredThenRequestHasPullPolicy() {
219-
this.buildImage.getPullPolicy().set(PullPolicy.NEVER.toString());
219+
this.buildImage.getPullPolicy().set(PullPolicy.NEVER);
220220
assertThat(this.buildImage.createRequest().getPullPolicy()).isEqualTo(PullPolicy.NEVER);
221221
}
222222

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests-buildsImageWithPullPolicy.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.springframework.boot.buildpack.platform.build.PullPolicy;
2+
13
plugins {
24
id 'java'
35
id 'org.springframework.boot' version '{version}'
@@ -12,4 +14,5 @@ targetCompatibility = '1.8'
1214

1315
bootBuildImage {
1416
builder = "projects.registry.vmware.com/springboot/spring-boot-cnb-builder:0.0.1"
17+
pullPolicy = PullPolicy.ALWAYS
1518
}

0 commit comments

Comments
 (0)