Update spring-boot-maven-plugin to use docker-test plugin

See gh-41228
This commit is contained in:
Andy Wilkinson 2024-06-25 16:28:33 +01:00
parent 7d5a761d51
commit 89a06608d2
66 changed files with 55 additions and 36 deletions

View File

@ -3,6 +3,7 @@ plugins {
id "org.springframework.boot.conventions"
id "org.springframework.boot.maven-plugin"
id "org.springframework.boot.optional-dependencies"
id "org.springframework.boot.docker-test"
}
description = "Spring Boot Maven Plugin"
@ -25,6 +26,15 @@ dependencies {
exclude(group: "javax.enterprise", module: "cdi-api")
exclude(group: "javax.inject", module: "javax.inject")
}
dockerTestImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
dockerTestImplementation("org.apache.maven.shared:maven-invoker") {
exclude(group: "javax.inject", module: "javax.inject")
}
dockerTestImplementation("org.assertj:assertj-core")
dockerTestImplementation("org.junit.jupiter:junit-jupiter")
dockerTestImplementation("org.testcontainers:junit-jupiter")
dockerTestImplementation("org.testcontainers:testcontainers")
implementation(project(":spring-boot-project:spring-boot-tools:spring-boot-buildpack-platform"))
implementation(project(":spring-boot-project:spring-boot-tools:spring-boot-loader-tools"))
@ -47,8 +57,6 @@ dependencies {
}
intTestImplementation("org.assertj:assertj-core")
intTestImplementation("org.junit.jupiter:junit-jupiter")
intTestImplementation("org.testcontainers:testcontainers")
intTestImplementation("org.testcontainers:junit-jupiter")
mavenOptionalImplementation("org.apache.maven.plugins:maven-shade-plugin") {
exclude(group: "javax.annotation", module: "javax.annotation-api")
@ -97,6 +105,9 @@ sourceSets {
intTest {
output.dir("${buildDir}/generated-resources", builtBy: "extractVersionProperties")
}
dockerTest {
output.dir("${buildDir}/generated-resources", builtBy: "extractVersionProperties")
}
}
tasks.withType(org.asciidoctor.gradle.jvm.AbstractAsciidoctorTask) {
@ -180,3 +191,7 @@ tasks.named("documentPluginGoals") {
"test-run": "run"
]
}
tasks.named("dockerTest").configure {
dependsOn tasks.named("prepareMavenBinaries")
}

View File

@ -61,7 +61,7 @@ class BuildImageRegistryIntegrationTests extends AbstractArchiveIntegrationTests
void whenBuildImageIsInvokedWithPublish(MavenBuild mavenBuild) {
String repoName = "test-image";
String imageName = this.registryAddress + "/" + repoName;
mavenBuild.project("build-image-publish")
mavenBuild.project("dockerTest", "build-image-publish")
.goals("package")
.systemProperty("spring-boot.build-image.imageName", imageName)
.execute((project) -> {

View File

@ -57,7 +57,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void whenBuildImageIsInvokedWithoutRepackageTheArchiveIsRepackagedOnTheFly(MavenBuild mavenBuild) {
mavenBuild.project("build-image")
mavenBuild.project("dockerTest", "build-image")
.goals("package")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.prepare(this::writeLongNameResource)
@ -77,7 +77,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void whenBuildImageIsInvokedOnTheCommandLineWithoutRepackageTheArchiveIsRepackagedOnTheFly(MavenBuild mavenBuild) {
mavenBuild.project("build-image-cmd-line")
mavenBuild.project("dockerTest", "build-image-cmd-line")
.goals("spring-boot:build-image")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.prepare(this::writeLongNameResource)
@ -97,7 +97,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void whenBuildImageIsInvokedWithClassifierWithoutRepackageTheArchiveIsRepackagedOnTheFly(MavenBuild mavenBuild) {
mavenBuild.project("build-image-classifier")
mavenBuild.project("dockerTest", "build-image-classifier")
.goals("package")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.prepare(this::writeLongNameResource)
@ -118,7 +118,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void whenBuildImageIsInvokedWithClassifierSourceWithoutRepackageTheArchiveIsRepackagedOnTheFly(
MavenBuild mavenBuild) {
mavenBuild.project("build-image-classifier-source")
mavenBuild.project("dockerTest", "build-image-classifier-source")
.goals("package")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.prepare(this::writeLongNameResource)
@ -139,7 +139,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void whenBuildImageIsInvokedWithRepackageTheExistingArchiveIsUsed(MavenBuild mavenBuild) {
mavenBuild.project("build-image-with-repackage")
mavenBuild.project("dockerTest", "build-image-with-repackage")
.goals("package")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.prepare(this::writeLongNameResource)
@ -160,7 +160,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void whenBuildImageIsInvokedWithClassifierAndRepackageTheExistingArchiveIsUsed(MavenBuild mavenBuild) {
mavenBuild.project("build-image-classifier-with-repackage")
mavenBuild.project("dockerTest", "build-image-classifier-with-repackage")
.goals("package")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.prepare(this::writeLongNameResource)
@ -181,7 +181,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void whenBuildImageIsInvokedWithClassifierSourceAndRepackageTheExistingArchiveIsUsed(MavenBuild mavenBuild) {
mavenBuild.project("build-image-classifier-source-with-repackage")
mavenBuild.project("dockerTest", "build-image-classifier-source-with-repackage")
.goals("package")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.prepare(this::writeLongNameResource)
@ -203,7 +203,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void whenBuildImageIsInvokedWithWarPackaging(MavenBuild mavenBuild) {
mavenBuild.project("build-image-war-packaging")
mavenBuild.project("dockerTest", "build-image-war-packaging")
.goals("package")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.prepare(this::writeLongNameResource)
@ -223,7 +223,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void whenBuildImageIsInvokedWithCustomImageName(MavenBuild mavenBuild) {
mavenBuild.project("build-image-custom-name")
mavenBuild.project("dockerTest", "build-image-custom-name")
.goals("package")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.systemProperty("spring-boot.build-image.imageName", "example.com/test/property-ignored:pom-preferred")
@ -243,7 +243,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void whenBuildImageIsInvokedWithCommandLineParameters(MavenBuild mavenBuild) {
mavenBuild.project("build-image")
mavenBuild.project("dockerTest", "build-image")
.goals("package")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.systemProperty("spring-boot.build-image.imageName", "example.com/test/cmd-property-name:v1")
@ -266,7 +266,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void whenBuildImageIsInvokedWithCustomBuilderImageAndRunImage(MavenBuild mavenBuild) {
mavenBuild.project("build-image-custom-builder")
mavenBuild.project("dockerTest", "build-image-custom-builder")
.goals("package")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.execute((project) -> {
@ -281,7 +281,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void whenBuildImageIsInvokedWithEmptyEnvEntry(MavenBuild mavenBuild) {
mavenBuild.project("build-image-empty-env-entry")
mavenBuild.project("dockerTest", "build-image-empty-env-entry")
.goals("package")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.prepare(this::writeLongNameResource)
@ -297,7 +297,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void whenBuildImageIsInvokedWithZipPackaging(MavenBuild mavenBuild) {
mavenBuild.project("build-image-zip-packaging")
mavenBuild.project("dockerTest", "build-image-zip-packaging")
.goals("package")
.prepare(this::writeLongNameResource)
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
@ -314,7 +314,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void whenBuildImageIsInvokedWithBuildpacks(MavenBuild mavenBuild) {
mavenBuild.project("build-image-custom-buildpacks")
mavenBuild.project("dockerTest", "build-image-custom-buildpacks")
.goals("package")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.execute((project) -> {
@ -327,7 +327,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void whenBuildImageIsInvokedWithBinding(MavenBuild mavenBuild) {
mavenBuild.project("build-image-bindings")
mavenBuild.project("dockerTest", "build-image-bindings")
.goals("package")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.execute((project) -> {
@ -342,7 +342,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void whenBuildImageIsInvokedWithNetworkModeNone(MavenBuild mavenBuild) {
mavenBuild.project("build-image-network")
mavenBuild.project("dockerTest", "build-image-network")
.goals("package")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.execute((project) -> {
@ -356,7 +356,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void whenBuildImageIsInvokedOnMultiModuleProjectWithPackageGoal(MavenBuild mavenBuild) {
mavenBuild.project("build-image-multi-module")
mavenBuild.project("dockerTest", "build-image-multi-module")
.goals("package")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.execute((project) -> {
@ -369,7 +369,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void whenBuildImageIsInvokedWithTags(MavenBuild mavenBuild) {
mavenBuild.project("build-image-tags")
mavenBuild.project("dockerTest", "build-image-tags")
.goals("package")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.execute((project) -> {
@ -386,7 +386,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void whenBuildImageIsInvokedWithVolumeCaches(MavenBuild mavenBuild) {
String testBuildId = randomString();
mavenBuild.project("build-image-volume-caches")
mavenBuild.project("dockerTest", "build-image-volume-caches")
.goals("package")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.systemProperty("test-build-id", testBuildId)
@ -404,7 +404,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
+ "Docker Desktop on other OSs")
void whenBuildImageIsInvokedWithBindCaches(MavenBuild mavenBuild) {
String testBuildId = randomString();
mavenBuild.project("build-image-bind-caches")
mavenBuild.project("dockerTest", "build-image-bind-caches")
.goals("package")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.systemProperty("test-build-id", testBuildId)
@ -435,7 +435,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void whenBuildImageIsInvokedWithCreatedDate(MavenBuild mavenBuild) {
String testBuildId = randomString();
mavenBuild.project("build-image-created-date")
mavenBuild.project("dockerTest", "build-image-created-date")
.goals("package")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.systemProperty("test-build-id", testBuildId)
@ -453,7 +453,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void whenBuildImageIsInvokedWithCurrentCreatedDate(MavenBuild mavenBuild) {
String testBuildId = randomString();
mavenBuild.project("build-image-current-created-date")
mavenBuild.project("dockerTest", "build-image-current-created-date")
.goals("package")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.systemProperty("test-build-id", testBuildId)
@ -476,7 +476,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void whenBuildImageIsInvokedWithApplicationDirectory(MavenBuild mavenBuild) {
String testBuildId = randomString();
mavenBuild.project("build-image-app-dir")
mavenBuild.project("dockerTest", "build-image-app-dir")
.goals("package")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.systemProperty("test-build-id", testBuildId)
@ -491,7 +491,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void whenBuildImageIsInvokedWithEmptySecurityOptions(MavenBuild mavenBuild) {
String testBuildId = randomString();
mavenBuild.project("build-image-security-opts")
mavenBuild.project("dockerTest", "build-image-security-opts")
.goals("package")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.systemProperty("test-build-id", testBuildId)
@ -505,7 +505,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void failsWhenBuildImageIsInvokedOnMultiModuleProjectWithBuildImageGoal(MavenBuild mavenBuild) {
mavenBuild.project("build-image-multi-module")
mavenBuild.project("dockerTest", "build-image-multi-module")
.goals("spring-boot:build-image")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.executeAndFail((project) -> assertThat(buildLog(project)).contains("Error packaging archive for image"));
@ -513,7 +513,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void failsWhenBuilderFails(MavenBuild mavenBuild) {
mavenBuild.project("build-image-builder-error")
mavenBuild.project("dockerTest", "build-image-builder-error")
.goals("package")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.executeAndFail((project) -> assertThat(buildLog(project)).contains("Building image")
@ -524,7 +524,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void failsWithBuildpackNotInBuilder(MavenBuild mavenBuild) {
mavenBuild.project("build-image-bad-buildpack")
mavenBuild.project("dockerTest", "build-image-bad-buildpack")
.goals("package")
.systemProperty("spring-boot.build-image.pullPolicy", "IF_NOT_PRESENT")
.executeAndFail((project) -> assertThat(buildLog(project))
@ -533,7 +533,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void failsWhenFinalNameIsMisconfigured(MavenBuild mavenBuild) {
mavenBuild.project("build-image-final-name")
mavenBuild.project("dockerTest", "build-image-final-name")
.goals("package")
.executeAndFail((project) -> assertThat(buildLog(project)).contains("final-name.jar.original")
.contains("is required for building an image"));
@ -541,7 +541,7 @@ class BuildImageTests extends AbstractArchiveIntegrationTests {
@TestTemplate
void failsWhenCachesAreConfiguredTwice(MavenBuild mavenBuild) {
mavenBuild.project("build-image-caches-multiple")
mavenBuild.project("dockerTest", "build-image-caches-multiple")
.goals("package")
.executeAndFail((project) -> assertThat(buildLog(project))
.contains("Each image building cache can be configured only once"));

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -37,7 +37,7 @@ class EclipseM2eIntegrationTests {
@Test // gh-21992
void pluginPomIncludesOptionalShadeDependency() throws Exception {
String version = new Versions().get("project.version");
File repository = new File("build/int-test-maven-repository");
File repository = new File("build/test-maven-repository");
File pluginDirectory = new File(repository, "org/springframework/boot/spring-boot-maven-plugin/" + version);
File[] pomFiles = pluginDirectory.listFiles(this::isPomFile);
Arrays.sort(pomFiles, Comparator.comparing(File::getName));

View File

@ -96,7 +96,11 @@ class MavenBuild {
}
MavenBuild project(String project) {
this.projectDir = new File("src/intTest/projects/" + project);
return project("intTest", project);
}
MavenBuild project(String root, String project) {
this.projectDir = new File("src/" + root + "/projects/" + project);
return this;
}
@ -157,7 +161,7 @@ class MavenBuild {
});
String settingsXml = Files.readString(Paths.get("src", "intTest", "projects", "settings.xml"))
.replace("@localCentralUrl@", new File("build/int-test-maven-repository").toURI().toURL().toString())
.replace("@localCentralUrl@", new File("build/test-maven-repository").toURI().toURL().toString())
.replace("@localRepositoryPath@", new File("build/local-maven-repository").getAbsolutePath());
Files.writeString(destination.resolve("settings.xml"), settingsXml, StandardOpenOption.CREATE_NEW);
request.setBaseDirectory(this.temp);