Allow spring-boot-image-tests to run without an existing snapshot

Closes gh-28817
pull/28830/head
Andy Wilkinson 3 years ago
parent cd4d08d8c0
commit 4bd86a6e20

@ -186,16 +186,11 @@ public class GradleBuild {
}
public GradleRunner prepareRunner(String... arguments) throws IOException {
String scriptContent = FileCopyUtils.copyToString(new FileReader(this.script));
this.scriptProperties.put("bootVersion", getBootVersion());
this.scriptProperties.put("dependencyManagementPluginVersion", getDependencyManagementPluginVersion());
for (Entry<String, String> property : this.scriptProperties.entrySet()) {
scriptContent = scriptContent.replace("{" + property.getKey() + "}", property.getValue());
}
FileCopyUtils.copy(scriptContent, new FileWriter(new File(this.projectDir, "build" + this.dsl.getExtension())));
copyTransformedScript(this.script, new File(this.projectDir, "build" + this.dsl.getExtension()));
if (this.settings != null) {
FileCopyUtils.copy(new FileReader(this.settings),
new FileWriter(new File(this.projectDir, "settings.gradle")));
copyTransformedScript(this.settings, new File(this.projectDir, "settings.gradle"));
}
File repository = new File("src/test/resources/repository");
if (repository.exists()) {
@ -223,6 +218,14 @@ public class GradleBuild {
return gradleRunner.withArguments(allArguments);
}
private void copyTransformedScript(String script, File destination) throws IOException {
String scriptContent = FileCopyUtils.copyToString(new FileReader(script));
for (Entry<String, String> property : this.scriptProperties.entrySet()) {
scriptContent = scriptContent.replace("{" + property.getKey() + "}", property.getValue());
}
FileCopyUtils.copy(scriptContent, new FileWriter(destination));
}
private File getTestKitDir() {
File temp = new File(System.getProperty("java.io.tmpdir"));
String username = System.getProperty("user.name");

@ -7,12 +7,19 @@ plugins {
description = "Spring Boot Image Building Tests"
configurations {
app
providedRuntime {
extendsFrom dependencyManagement
}
}
task syncMavenRepository(type: Sync) {
from configurations.app
into "${buildDir}/system-test-maven-repository"
}
systemTest {
dependsOn syncMavenRepository
if (project.hasProperty("springBootVersion")) {
systemProperty "springBootVersion", project.properties["springBootVersion"]
} else {
@ -21,11 +28,15 @@ systemTest {
}
dependencies {
app project(path: ":spring-boot-project:spring-boot-tools:spring-boot-gradle-plugin", configuration: "mavenRepository")
app project(path: ":spring-boot-project:spring-boot-starters:spring-boot-starter-web", configuration: "mavenRepository")
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web")) {
exclude group: "org.hibernate.validator"
}
systemTestImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test"))
systemTestImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-gradle-plugin"))
systemTestImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-gradle-test-support"))
systemTestImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-buildpack-platform"))
systemTestImplementation(gradleTestKit())

@ -32,6 +32,7 @@ import com.github.dockerjava.api.model.ContainerConfig;
import org.assertj.core.api.Condition;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.TaskOutcome;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.testcontainers.containers.GenericContainer;
@ -61,6 +62,12 @@ class PaketoBuilderTests {
GradleBuild gradleBuild;
@BeforeEach
void configureGradleBuild() {
this.gradleBuild.scriptProperty("systemTestMavenRepository",
new File("build/system-test-maven-repository").getAbsoluteFile().toURI().toASCIIString());
}
@Test
void executableJarApp() throws Exception {
writeMainClass();

@ -6,6 +6,14 @@ plugins {
}
repositories {
exclusiveContent {
forRepository {
maven { url '{systemTestMavenRepository}' }
}
filter {
includeGroup "org.springframework.boot"
}
}
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }

@ -6,6 +6,14 @@ plugins {
}
repositories {
exclusiveContent {
forRepository {
maven { url '{systemTestMavenRepository}' }
}
filter {
includeGroup "org.springframework.boot"
}
}
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }

@ -6,6 +6,14 @@ plugins {
}
repositories {
exclusiveContent {
forRepository {
maven { url '{systemTestMavenRepository}' }
}
filter {
includeGroup "org.springframework.boot"
}
}
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }

@ -6,6 +6,14 @@ plugins {
}
repositories {
exclusiveContent {
forRepository {
maven { url '{systemTestMavenRepository}' }
}
filter {
includeGroup "org.springframework.boot"
}
}
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }

@ -5,6 +5,14 @@ plugins {
}
repositories {
exclusiveContent {
forRepository {
maven { url '{systemTestMavenRepository}' }
}
filter {
includeGroup "org.springframework.boot"
}
}
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }

@ -1,7 +1,22 @@
pluginManagement {
repositories {
exclusiveContent {
forRepository {
maven { url '{systemTestMavenRepository}' }
}
filter {
includeGroup "org.springframework.boot"
}
}
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
gradlePluginPortal()
}
resolutionStrategy {
eachPlugin {
if (requested.id.id == "org.springframework.boot") {
useModule "org.springframework.boot:spring-boot-gradle-plugin:${requested.version}"
}
}
}
}
Loading…
Cancel
Save