Skip to content

Commit 89a0660

Browse files
committed
Update spring-boot-maven-plugin to use docker-test plugin
See gh-41228
1 parent 7d5a761 commit 89a0660

File tree

66 files changed

+55
-36
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+55
-36
lines changed

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/build.gradle

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ plugins {
33
id "org.springframework.boot.conventions"
44
id "org.springframework.boot.maven-plugin"
55
id "org.springframework.boot.optional-dependencies"
6+
id "org.springframework.boot.docker-test"
67
}
78

89
description = "Spring Boot Maven Plugin"
@@ -25,6 +26,15 @@ dependencies {
2526
exclude(group: "javax.enterprise", module: "cdi-api")
2627
exclude(group: "javax.inject", module: "javax.inject")
2728
}
29+
30+
dockerTestImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
31+
dockerTestImplementation("org.apache.maven.shared:maven-invoker") {
32+
exclude(group: "javax.inject", module: "javax.inject")
33+
}
34+
dockerTestImplementation("org.assertj:assertj-core")
35+
dockerTestImplementation("org.junit.jupiter:junit-jupiter")
36+
dockerTestImplementation("org.testcontainers:junit-jupiter")
37+
dockerTestImplementation("org.testcontainers:testcontainers")
2838

2939
implementation(project(":spring-boot-project:spring-boot-tools:spring-boot-buildpack-platform"))
3040
implementation(project(":spring-boot-project:spring-boot-tools:spring-boot-loader-tools"))
@@ -47,8 +57,6 @@ dependencies {
4757
}
4858
intTestImplementation("org.assertj:assertj-core")
4959
intTestImplementation("org.junit.jupiter:junit-jupiter")
50-
intTestImplementation("org.testcontainers:testcontainers")
51-
intTestImplementation("org.testcontainers:junit-jupiter")
5260

5361
mavenOptionalImplementation("org.apache.maven.plugins:maven-shade-plugin") {
5462
exclude(group: "javax.annotation", module: "javax.annotation-api")
@@ -97,6 +105,9 @@ sourceSets {
97105
intTest {
98106
output.dir("${buildDir}/generated-resources", builtBy: "extractVersionProperties")
99107
}
108+
dockerTest {
109+
output.dir("${buildDir}/generated-resources", builtBy: "extractVersionProperties")
110+
}
100111
}
101112

102113
tasks.withType(org.asciidoctor.gradle.jvm.AbstractAsciidoctorTask) {
@@ -180,3 +191,7 @@ tasks.named("documentPluginGoals") {
180191
"test-run": "run"
181192
]
182193
}
194+
195+
tasks.named("dockerTest").configure {
196+
dependsOn tasks.named("prepareMavenBinaries")
197+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void setUp() {
6161
void whenBuildImageIsInvokedWithPublish(MavenBuild mavenBuild) {
6262
String repoName = "test-image";
6363
String imageName = this.registryAddress + "/" + repoName;
64-
mavenBuild.project("build-image-publish")
64+
mavenBuild.project("dockerTest", "build-image-publish")
6565
.goals("package")
6666
.systemProperty("spring-boot.build-image.imageName", imageName)
6767
.execute((project) -> {
Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
5757

5858
@TestTemplate
5959
void whenBuildImageIsInvokedWithoutRepackageTheArchiveIsRepackagedOnTheFly(MavenBuild mavenBuild) {
60-
mavenBuild.project("build-image")
60+
mavenBuild.project("dockerTest", "build-image")
6161
.goals("package")
6262
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
6363
.prepare(this::writeLongNameResource)
@@ -77,7 +77,7 @@ void whenBuildImageIsInvokedWithoutRepackageTheArchiveIsRepackagedOnTheFly(Maven
7777

7878
@TestTemplate
7979
void whenBuildImageIsInvokedOnTheCommandLineWithoutRepackageTheArchiveIsRepackagedOnTheFly(MavenBuild mavenBuild) {
80-
mavenBuild.project("build-image-cmd-line")
80+
mavenBuild.project("dockerTest", "build-image-cmd-line")
8181
.goals("spring-boot:build-image")
8282
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
8383
.prepare(this::writeLongNameResource)
@@ -97,7 +97,7 @@ void whenBuildImageIsInvokedOnTheCommandLineWithoutRepackageTheArchiveIsRepackag
9797

9898
@TestTemplate
9999
void whenBuildImageIsInvokedWithClassifierWithoutRepackageTheArchiveIsRepackagedOnTheFly(MavenBuild mavenBuild) {
100-
mavenBuild.project("build-image-classifier")
100+
mavenBuild.project("dockerTest", "build-image-classifier")
101101
.goals("package")
102102
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
103103
.prepare(this::writeLongNameResource)
@@ -118,7 +118,7 @@ void whenBuildImageIsInvokedWithClassifierWithoutRepackageTheArchiveIsRepackaged
118118
@TestTemplate
119119
void whenBuildImageIsInvokedWithClassifierSourceWithoutRepackageTheArchiveIsRepackagedOnTheFly(
120120
MavenBuild mavenBuild) {
121-
mavenBuild.project("build-image-classifier-source")
121+
mavenBuild.project("dockerTest", "build-image-classifier-source")
122122
.goals("package")
123123
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
124124
.prepare(this::writeLongNameResource)
@@ -139,7 +139,7 @@ void whenBuildImageIsInvokedWithClassifierSourceWithoutRepackageTheArchiveIsRepa
139139

140140
@TestTemplate
141141
void whenBuildImageIsInvokedWithRepackageTheExistingArchiveIsUsed(MavenBuild mavenBuild) {
142-
mavenBuild.project("build-image-with-repackage")
142+
mavenBuild.project("dockerTest", "build-image-with-repackage")
143143
.goals("package")
144144
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
145145
.prepare(this::writeLongNameResource)
@@ -160,7 +160,7 @@ void whenBuildImageIsInvokedWithRepackageTheExistingArchiveIsUsed(MavenBuild mav
160160

161161
@TestTemplate
162162
void whenBuildImageIsInvokedWithClassifierAndRepackageTheExistingArchiveIsUsed(MavenBuild mavenBuild) {
163-
mavenBuild.project("build-image-classifier-with-repackage")
163+
mavenBuild.project("dockerTest", "build-image-classifier-with-repackage")
164164
.goals("package")
165165
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
166166
.prepare(this::writeLongNameResource)
@@ -181,7 +181,7 @@ void whenBuildImageIsInvokedWithClassifierAndRepackageTheExistingArchiveIsUsed(M
181181

182182
@TestTemplate
183183
void whenBuildImageIsInvokedWithClassifierSourceAndRepackageTheExistingArchiveIsUsed(MavenBuild mavenBuild) {
184-
mavenBuild.project("build-image-classifier-source-with-repackage")
184+
mavenBuild.project("dockerTest", "build-image-classifier-source-with-repackage")
185185
.goals("package")
186186
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
187187
.prepare(this::writeLongNameResource)
@@ -203,7 +203,7 @@ void whenBuildImageIsInvokedWithClassifierSourceAndRepackageTheExistingArchiveIs
203203

204204
@TestTemplate
205205
void whenBuildImageIsInvokedWithWarPackaging(MavenBuild mavenBuild) {
206-
mavenBuild.project("build-image-war-packaging")
206+
mavenBuild.project("dockerTest", "build-image-war-packaging")
207207
.goals("package")
208208
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
209209
.prepare(this::writeLongNameResource)
@@ -223,7 +223,7 @@ void whenBuildImageIsInvokedWithWarPackaging(MavenBuild mavenBuild) {
223223

224224
@TestTemplate
225225
void whenBuildImageIsInvokedWithCustomImageName(MavenBuild mavenBuild) {
226-
mavenBuild.project("build-image-custom-name")
226+
mavenBuild.project("dockerTest", "build-image-custom-name")
227227
.goals("package")
228228
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
229229
.systemProperty("spring-boot.build-image.imageName", "example.com/test/property-ignored:pom-preferred")
@@ -243,7 +243,7 @@ void whenBuildImageIsInvokedWithCustomImageName(MavenBuild mavenBuild) {
243243

244244
@TestTemplate
245245
void whenBuildImageIsInvokedWithCommandLineParameters(MavenBuild mavenBuild) {
246-
mavenBuild.project("build-image")
246+
mavenBuild.project("dockerTest", "build-image")
247247
.goals("package")
248248
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
249249
.systemProperty("spring-boot.build-image.imageName", "example.com/test/cmd-property-name:v1")
@@ -266,7 +266,7 @@ void whenBuildImageIsInvokedWithCommandLineParameters(MavenBuild mavenBuild) {
266266

267267
@TestTemplate
268268
void whenBuildImageIsInvokedWithCustomBuilderImageAndRunImage(MavenBuild mavenBuild) {
269-
mavenBuild.project("build-image-custom-builder")
269+
mavenBuild.project("dockerTest", "build-image-custom-builder")
270270
.goals("package")
271271
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
272272
.execute((project) -> {
@@ -281,7 +281,7 @@ void whenBuildImageIsInvokedWithCustomBuilderImageAndRunImage(MavenBuild mavenBu
281281

282282
@TestTemplate
283283
void whenBuildImageIsInvokedWithEmptyEnvEntry(MavenBuild mavenBuild) {
284-
mavenBuild.project("build-image-empty-env-entry")
284+
mavenBuild.project("dockerTest", "build-image-empty-env-entry")
285285
.goals("package")
286286
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
287287
.prepare(this::writeLongNameResource)
@@ -297,7 +297,7 @@ void whenBuildImageIsInvokedWithEmptyEnvEntry(MavenBuild mavenBuild) {
297297

298298
@TestTemplate
299299
void whenBuildImageIsInvokedWithZipPackaging(MavenBuild mavenBuild) {
300-
mavenBuild.project("build-image-zip-packaging")
300+
mavenBuild.project("dockerTest", "build-image-zip-packaging")
301301
.goals("package")
302302
.prepare(this::writeLongNameResource)
303303
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
@@ -314,7 +314,7 @@ void whenBuildImageIsInvokedWithZipPackaging(MavenBuild mavenBuild) {
314314

315315
@TestTemplate
316316
void whenBuildImageIsInvokedWithBuildpacks(MavenBuild mavenBuild) {
317-
mavenBuild.project("build-image-custom-buildpacks")
317+
mavenBuild.project("dockerTest", "build-image-custom-buildpacks")
318318
.goals("package")
319319
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
320320
.execute((project) -> {
@@ -327,7 +327,7 @@ void whenBuildImageIsInvokedWithBuildpacks(MavenBuild mavenBuild) {
327327

328328
@TestTemplate
329329
void whenBuildImageIsInvokedWithBinding(MavenBuild mavenBuild) {
330-
mavenBuild.project("build-image-bindings")
330+
mavenBuild.project("dockerTest", "build-image-bindings")
331331
.goals("package")
332332
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
333333
.execute((project) -> {
@@ -342,7 +342,7 @@ void whenBuildImageIsInvokedWithBinding(MavenBuild mavenBuild) {
342342

343343
@TestTemplate
344344
void whenBuildImageIsInvokedWithNetworkModeNone(MavenBuild mavenBuild) {
345-
mavenBuild.project("build-image-network")
345+
mavenBuild.project("dockerTest", "build-image-network")
346346
.goals("package")
347347
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
348348
.execute((project) -> {
@@ -356,7 +356,7 @@ void whenBuildImageIsInvokedWithNetworkModeNone(MavenBuild mavenBuild) {
356356

357357
@TestTemplate
358358
void whenBuildImageIsInvokedOnMultiModuleProjectWithPackageGoal(MavenBuild mavenBuild) {
359-
mavenBuild.project("build-image-multi-module")
359+
mavenBuild.project("dockerTest", "build-image-multi-module")
360360
.goals("package")
361361
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
362362
.execute((project) -> {
@@ -369,7 +369,7 @@ void whenBuildImageIsInvokedOnMultiModuleProjectWithPackageGoal(MavenBuild maven
369369

370370
@TestTemplate
371371
void whenBuildImageIsInvokedWithTags(MavenBuild mavenBuild) {
372-
mavenBuild.project("build-image-tags")
372+
mavenBuild.project("dockerTest", "build-image-tags")
373373
.goals("package")
374374
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
375375
.execute((project) -> {
@@ -386,7 +386,7 @@ void whenBuildImageIsInvokedWithTags(MavenBuild mavenBuild) {
386386
@TestTemplate
387387
void whenBuildImageIsInvokedWithVolumeCaches(MavenBuild mavenBuild) {
388388
String testBuildId = randomString();
389-
mavenBuild.project("build-image-volume-caches")
389+
mavenBuild.project("dockerTest", "build-image-volume-caches")
390390
.goals("package")
391391
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
392392
.systemProperty("test-build-id", testBuildId)
@@ -404,7 +404,7 @@ void whenBuildImageIsInvokedWithVolumeCaches(MavenBuild mavenBuild) {
404404
+ "Docker Desktop on other OSs")
405405
void whenBuildImageIsInvokedWithBindCaches(MavenBuild mavenBuild) {
406406
String testBuildId = randomString();
407-
mavenBuild.project("build-image-bind-caches")
407+
mavenBuild.project("dockerTest", "build-image-bind-caches")
408408
.goals("package")
409409
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
410410
.systemProperty("test-build-id", testBuildId)
@@ -435,7 +435,7 @@ private static void cleanupCache(Path buildCachePath) {
435435
@TestTemplate
436436
void whenBuildImageIsInvokedWithCreatedDate(MavenBuild mavenBuild) {
437437
String testBuildId = randomString();
438-
mavenBuild.project("build-image-created-date")
438+
mavenBuild.project("dockerTest", "build-image-created-date")
439439
.goals("package")
440440
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
441441
.systemProperty("test-build-id", testBuildId)
@@ -453,7 +453,7 @@ void whenBuildImageIsInvokedWithCreatedDate(MavenBuild mavenBuild) {
453453
@TestTemplate
454454
void whenBuildImageIsInvokedWithCurrentCreatedDate(MavenBuild mavenBuild) {
455455
String testBuildId = randomString();
456-
mavenBuild.project("build-image-current-created-date")
456+
mavenBuild.project("dockerTest", "build-image-current-created-date")
457457
.goals("package")
458458
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
459459
.systemProperty("test-build-id", testBuildId)
@@ -476,7 +476,7 @@ void whenBuildImageIsInvokedWithCurrentCreatedDate(MavenBuild mavenBuild) {
476476
@TestTemplate
477477
void whenBuildImageIsInvokedWithApplicationDirectory(MavenBuild mavenBuild) {
478478
String testBuildId = randomString();
479-
mavenBuild.project("build-image-app-dir")
479+
mavenBuild.project("dockerTest", "build-image-app-dir")
480480
.goals("package")
481481
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
482482
.systemProperty("test-build-id", testBuildId)
@@ -491,7 +491,7 @@ void whenBuildImageIsInvokedWithApplicationDirectory(MavenBuild mavenBuild) {
491491
@TestTemplate
492492
void whenBuildImageIsInvokedWithEmptySecurityOptions(MavenBuild mavenBuild) {
493493
String testBuildId = randomString();
494-
mavenBuild.project("build-image-security-opts")
494+
mavenBuild.project("dockerTest", "build-image-security-opts")
495495
.goals("package")
496496
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
497497
.systemProperty("test-build-id", testBuildId)
@@ -505,15 +505,15 @@ void whenBuildImageIsInvokedWithEmptySecurityOptions(MavenBuild mavenBuild) {
505505

506506
@TestTemplate
507507
void failsWhenBuildImageIsInvokedOnMultiModuleProjectWithBuildImageGoal(MavenBuild mavenBuild) {
508-
mavenBuild.project("build-image-multi-module")
508+
mavenBuild.project("dockerTest", "build-image-multi-module")
509509
.goals("spring-boot:build-image")
510510
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
511511
.executeAndFail((project) -> assertThat(buildLog(project)).contains("Error packaging archive for image"));
512512
}
513513

514514
@TestTemplate
515515
void failsWhenBuilderFails(MavenBuild mavenBuild) {
516-
mavenBuild.project("build-image-builder-error")
516+
mavenBuild.project("dockerTest", "build-image-builder-error")
517517
.goals("package")
518518
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
519519
.executeAndFail((project) -> assertThat(buildLog(project)).contains("Building image")
@@ -524,7 +524,7 @@ void failsWhenBuilderFails(MavenBuild mavenBuild) {
524524

525525
@TestTemplate
526526
void failsWithBuildpackNotInBuilder(MavenBuild mavenBuild) {
527-
mavenBuild.project("build-image-bad-buildpack")
527+
mavenBuild.project("dockerTest", "build-image-bad-buildpack")
528528
.goals("package")
529529
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
530530
.executeAndFail((project) -> assertThat(buildLog(project))
@@ -533,15 +533,15 @@ void failsWithBuildpackNotInBuilder(MavenBuild mavenBuild) {
533533

534534
@TestTemplate
535535
void failsWhenFinalNameIsMisconfigured(MavenBuild mavenBuild) {
536-
mavenBuild.project("build-image-final-name")
536+
mavenBuild.project("dockerTest", "build-image-final-name")
537537
.goals("package")
538538
.executeAndFail((project) -> assertThat(buildLog(project)).contains("final-name.jar.original")
539539
.contains("is required for building an image"));
540540
}
541541

542542
@TestTemplate
543543
void failsWhenCachesAreConfiguredTwice(MavenBuild mavenBuild) {
544-
mavenBuild.project("build-image-caches-multiple")
544+
mavenBuild.project("dockerTest", "build-image-caches-multiple")
545545
.goals("package")
546546
.executeAndFail((project) -> assertThat(buildLog(project))
547547
.contains("Each image building cache can be configured only once"));

0 commit comments

Comments
 (0)