Skip to content

Commit 142a38f

Browse files
committed
Merge pull request #32719 from kedar-joshi
* pr/23719: Polish "Allow overriding image.cleanCache from the command-line" Allow overriding image.cleanCache from the command-line Closes gh-32719
2 parents 771503f + 59bcbd4 commit 142a38f

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/docs/asciidoc/packaging-oci-image.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ Acceptable values are `ALWAYS`, `NEVER`, and `IF_NOT_PRESENT`.
153153

154154
| `cleanCache`
155155
| Whether to clean the cache before building.
156-
|
156+
| `spring-boot.build-image.cleanCache`
157157
| `false`
158158

159159
| `verboseLogging`

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildImageMojo.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ public class BuildImageMojo extends AbstractPackagerMojo {
130130
@Parameter(property = "spring-boot.build-image.runImage", readonly = true)
131131
String runImage;
132132

133+
/**
134+
* Alias for {@link Image#cleanCache} to support configuration via command-line
135+
* property.
136+
* @since 2.4.0
137+
*/
138+
@Parameter(property = "spring-boot.build-image.cleanCache", readonly = true)
139+
Boolean cleanCache;
140+
133141
/**
134142
* Alias for {@link Image#pullPolicy} to support configuration via command-line
135143
* property.
@@ -189,6 +197,9 @@ private BuildRequest getBuildRequest(Libraries libraries) throws MojoExecutionEx
189197
if (image.runImage == null && this.runImage != null) {
190198
image.setRunImage(this.runImage);
191199
}
200+
if (image.cleanCache == null && this.cleanCache != null) {
201+
image.setCleanCache(this.cleanCache);
202+
}
192203
if (image.pullPolicy == null && this.pullPolicy != null) {
193204
image.setPullPolicy(this.pullPolicy);
194205
}

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/Image.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class Image {
4646

4747
Map<String, String> env;
4848

49-
boolean cleanCache;
49+
Boolean cleanCache;
5050

5151
boolean verboseLogging;
5252

@@ -102,10 +102,14 @@ public Map<String, String> getEnv() {
102102
* If the cache should be cleaned before building.
103103
* @return {@code true} if the cache should be cleaned
104104
*/
105-
public boolean isCleanCache() {
105+
public Boolean getCleanCache() {
106106
return this.cleanCache;
107107
}
108108

109+
void setCleanCache(Boolean cleanCache) {
110+
this.cleanCache = cleanCache;
111+
}
112+
109113
/**
110114
* If verbose logging is required.
111115
* @return {@code true} for verbose logging
@@ -160,7 +164,9 @@ private BuildRequest customize(BuildRequest request) {
160164
if (this.env != null && !this.env.isEmpty()) {
161165
request = request.withEnv(this.env);
162166
}
163-
request = request.withCleanCache(this.cleanCache);
167+
if (this.cleanCache != null) {
168+
request = request.withCleanCache(this.cleanCache);
169+
}
164170
request = request.withVerboseLogging(this.verboseLogging);
165171
if (this.pullPolicy != null) {
166172
request = request.withPullPolicy(this.pullPolicy);

0 commit comments

Comments
 (0)