Skip to content

Commit 4bd86a6

Browse files
committed
Allow spring-boot-image-tests to run without an existing snapshot
Closes gh-28817
1 parent cd4d08d commit 4bd86a6

File tree

9 files changed

+83
-7
lines changed

9 files changed

+83
-7
lines changed

spring-boot-project/spring-boot-tools/spring-boot-gradle-test-support/src/main/java/org/springframework/boot/testsupport/gradle/testkit/GradleBuild.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,11 @@ public BuildResult buildAndFail(String... arguments) {
186186
}
187187

188188
public GradleRunner prepareRunner(String... arguments) throws IOException {
189-
String scriptContent = FileCopyUtils.copyToString(new FileReader(this.script));
190189
this.scriptProperties.put("bootVersion", getBootVersion());
191190
this.scriptProperties.put("dependencyManagementPluginVersion", getDependencyManagementPluginVersion());
192-
for (Entry<String, String> property : this.scriptProperties.entrySet()) {
193-
scriptContent = scriptContent.replace("{" + property.getKey() + "}", property.getValue());
194-
}
195-
FileCopyUtils.copy(scriptContent, new FileWriter(new File(this.projectDir, "build" + this.dsl.getExtension())));
191+
copyTransformedScript(this.script, new File(this.projectDir, "build" + this.dsl.getExtension()));
196192
if (this.settings != null) {
197-
FileCopyUtils.copy(new FileReader(this.settings),
198-
new FileWriter(new File(this.projectDir, "settings.gradle")));
193+
copyTransformedScript(this.settings, new File(this.projectDir, "settings.gradle"));
199194
}
200195
File repository = new File("src/test/resources/repository");
201196
if (repository.exists()) {
@@ -223,6 +218,14 @@ public GradleRunner prepareRunner(String... arguments) throws IOException {
223218
return gradleRunner.withArguments(allArguments);
224219
}
225220

221+
private void copyTransformedScript(String script, File destination) throws IOException {
222+
String scriptContent = FileCopyUtils.copyToString(new FileReader(script));
223+
for (Entry<String, String> property : this.scriptProperties.entrySet()) {
224+
scriptContent = scriptContent.replace("{" + property.getKey() + "}", property.getValue());
225+
}
226+
FileCopyUtils.copy(scriptContent, new FileWriter(destination));
227+
}
228+
226229
private File getTestKitDir() {
227230
File temp = new File(System.getProperty("java.io.tmpdir"));
228231
String username = System.getProperty("user.name");

spring-boot-system-tests/spring-boot-image-tests/build.gradle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@ plugins {
77
description = "Spring Boot Image Building Tests"
88

99
configurations {
10+
app
1011
providedRuntime {
1112
extendsFrom dependencyManagement
1213
}
1314
}
1415

16+
task syncMavenRepository(type: Sync) {
17+
from configurations.app
18+
into "${buildDir}/system-test-maven-repository"
19+
}
20+
1521
systemTest {
22+
dependsOn syncMavenRepository
1623
if (project.hasProperty("springBootVersion")) {
1724
systemProperty "springBootVersion", project.properties["springBootVersion"]
1825
} else {
@@ -21,11 +28,15 @@ systemTest {
2128
}
2229

2330
dependencies {
31+
app project(path: ":spring-boot-project:spring-boot-tools:spring-boot-gradle-plugin", configuration: "mavenRepository")
32+
app project(path: ":spring-boot-project:spring-boot-starters:spring-boot-starter-web", configuration: "mavenRepository")
33+
2434
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web")) {
2535
exclude group: "org.hibernate.validator"
2636
}
2737

2838
systemTestImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test"))
39+
systemTestImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-gradle-plugin"))
2940
systemTestImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-gradle-test-support"))
3041
systemTestImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-buildpack-platform"))
3142
systemTestImplementation(gradleTestKit())

spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/paketo/PaketoBuilderTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.assertj.core.api.Condition;
3333
import org.gradle.testkit.runner.BuildResult;
3434
import org.gradle.testkit.runner.TaskOutcome;
35+
import org.junit.jupiter.api.BeforeEach;
3536
import org.junit.jupiter.api.Test;
3637
import org.junit.jupiter.api.extension.ExtendWith;
3738
import org.testcontainers.containers.GenericContainer;
@@ -61,6 +62,12 @@ class PaketoBuilderTests {
6162

6263
GradleBuild gradleBuild;
6364

65+
@BeforeEach
66+
void configureGradleBuild() {
67+
this.gradleBuild.scriptProperty("systemTestMavenRepository",
68+
new File("build/system-test-maven-repository").getAbsoluteFile().toURI().toASCIIString());
69+
}
70+
6471
@Test
6572
void executableJarApp() throws Exception {
6673
writeMainClass();

spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-bootDistZipJarApp.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ plugins {
66
}
77

88
repositories {
9+
exclusiveContent {
10+
forRepository {
11+
maven { url '{systemTestMavenRepository}' }
12+
}
13+
filter {
14+
includeGroup "org.springframework.boot"
15+
}
16+
}
917
mavenCentral()
1018
maven { url 'https://repo.spring.io/milestone' }
1119
maven { url 'https://repo.spring.io/snapshot' }

spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-executableWarApp.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ plugins {
66
}
77

88
repositories {
9+
exclusiveContent {
10+
forRepository {
11+
maven { url '{systemTestMavenRepository}' }
12+
}
13+
filter {
14+
includeGroup "org.springframework.boot"
15+
}
16+
}
917
mavenCentral()
1018
maven { url 'https://repo.spring.io/milestone' }
1119
maven { url 'https://repo.spring.io/snapshot' }

spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-plainDistZipJarApp.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ plugins {
66
}
77

88
repositories {
9+
exclusiveContent {
10+
forRepository {
11+
maven { url '{systemTestMavenRepository}' }
12+
}
13+
filter {
14+
includeGroup "org.springframework.boot"
15+
}
16+
}
917
mavenCentral()
1018
maven { url 'https://repo.spring.io/milestone' }
1119
maven { url 'https://repo.spring.io/snapshot' }

spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests-plainWarApp.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ plugins {
66
}
77

88
repositories {
9+
exclusiveContent {
10+
forRepository {
11+
maven { url '{systemTestMavenRepository}' }
12+
}
13+
filter {
14+
includeGroup "org.springframework.boot"
15+
}
16+
}
917
mavenCentral()
1018
maven { url 'https://repo.spring.io/milestone' }
1119
maven { url 'https://repo.spring.io/snapshot' }

spring-boot-system-tests/spring-boot-image-tests/src/systemTest/resources/org/springframework/boot/image/paketo/PaketoBuilderTests.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ plugins {
55
}
66

77
repositories {
8+
exclusiveContent {
9+
forRepository {
10+
maven { url '{systemTestMavenRepository}' }
11+
}
12+
filter {
13+
includeGroup "org.springframework.boot"
14+
}
15+
}
816
mavenCentral()
917
maven { url 'https://repo.spring.io/milestone' }
1018
maven { url 'https://repo.spring.io/snapshot' }
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
pluginManagement {
22
repositories {
3+
exclusiveContent {
4+
forRepository {
5+
maven { url '{systemTestMavenRepository}' }
6+
}
7+
filter {
8+
includeGroup "org.springframework.boot"
9+
}
10+
}
311
maven { url 'https://repo.spring.io/milestone' }
412
maven { url 'https://repo.spring.io/snapshot' }
513
gradlePluginPortal()
614
}
15+
resolutionStrategy {
16+
eachPlugin {
17+
if (requested.id.id == "org.springframework.boot") {
18+
useModule "org.springframework.boot:spring-boot-gradle-plugin:${requested.version}"
19+
}
20+
}
21+
}
722
}

0 commit comments

Comments
 (0)