Add testAndDevelopmentOnly configuration
Closes gh-35436
This commit is contained in:
@@ -142,7 +142,52 @@ class JavaPluginActionIntegrationTests {
|
||||
|
||||
@TestTemplate
|
||||
void applyingJavaPluginCreatesDevelopmentOnlyConfiguration() {
|
||||
assertThat(this.gradleBuild.build("build").getOutput()).contains("developmentOnly exists = true");
|
||||
assertThat(this.gradleBuild.build("help").getOutput()).contains("developmentOnly exists = true");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void applyingJavaPluginCreatesTestAndDevelopmentOnlyConfiguration() {
|
||||
assertThat(this.gradleBuild.build("help").getOutput()).contains("testAndDevelopmentOnly exists = true");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void testCompileClasspathIncludesTestAndDevelopmentOnlyDependencies() {
|
||||
assertThat(this.gradleBuild.build("help").getOutput()).contains("commons-lang3-3.12.0.jar");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void testRuntimeClasspathIncludesTestAndDevelopmentOnlyDependencies() {
|
||||
assertThat(this.gradleBuild.build("help").getOutput()).contains("commons-lang3-3.12.0.jar");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void testCompileClasspathDoesNotIncludeDevelopmentOnlyDependencies() {
|
||||
assertThat(this.gradleBuild.build("help").getOutput()).doesNotContain("commons-lang3-3.12.0.jar");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void testRuntimeClasspathDoesNotIncludeDevelopmentOnlyDependencies() {
|
||||
assertThat(this.gradleBuild.build("help").getOutput()).doesNotContain("commons-lang3-3.12.0.jar");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void compileClasspathDoesNotIncludeTestAndDevelopmentOnlyDependencies() {
|
||||
assertThat(this.gradleBuild.build("help").getOutput()).doesNotContain("commons-lang3-3.12.0.jar");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void runtimeClasspathIncludesTestAndDevelopmentOnlyDependencies() {
|
||||
assertThat(this.gradleBuild.build("help").getOutput()).contains("commons-lang3-3.12.0.jar");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void compileClasspathDoesNotIncludeDevelopmentOnlyDependencies() {
|
||||
assertThat(this.gradleBuild.build("help").getOutput()).doesNotContain("commons-lang3-3.12.0.jar");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void runtimeClasspathIncludesDevelopmentOnlyDependencies() {
|
||||
assertThat(this.gradleBuild.build("help").getOutput()).contains("commons-lang3-3.12.0.jar");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
|
||||
@@ -105,6 +105,14 @@ class NativeImagePluginActionIntegrationTests {
|
||||
assertThat(result.getOutput()).doesNotContain("commons-lang");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void testAndDevelopmentOnlyDependenciesDoNotAppearInNativeImageClasspath() {
|
||||
writeDummySpringApplicationAotProcessorMainClass();
|
||||
BuildResult result = this.gradleBuild.expectDeprecationWarningsWithAtLeastVersion("8.2-rc-1")
|
||||
.build("checkNativeImageClasspath");
|
||||
assertThat(result.getOutput()).doesNotContain("commons-lang");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void classesGeneratedDuringAotProcessingAreOnTheNativeImageClasspath() {
|
||||
BuildResult result = this.gradleBuild.expectDeprecationWarningsWithAtLeastVersion("8.2-rc-1")
|
||||
|
||||
@@ -106,10 +106,22 @@ class SpringBootAotPluginIntegrationTests {
|
||||
|
||||
@TestTemplate
|
||||
void processTestAotDoesNotHaveDevelopmentOnlyDependenciesOnItsClasspath() {
|
||||
String output = this.gradleBuild.build("processTestAotClasspath", "--stacktrace").getOutput();
|
||||
String output = this.gradleBuild.build("processTestAotClasspath").getOutput();
|
||||
assertThat(output).doesNotContain("commons-lang");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void processAotDoesNotHaveTestAndDevelopmentOnlyDependenciesOnItsClasspath() {
|
||||
String output = this.gradleBuild.build("processAotClasspath").getOutput();
|
||||
assertThat(output).doesNotContain("commons-lang");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void processTestAotHasTestAndDevelopmentOnlyDependenciesOnItsClasspath() {
|
||||
String output = this.gradleBuild.build("processTestAotClasspath").getOutput();
|
||||
assertThat(output).contains("commons-lang");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void processAotRunsWhenProjectHasMainSource() throws IOException {
|
||||
writeMainClass("org.springframework.boot", "SpringApplicationAotProcessor");
|
||||
|
||||
@@ -221,6 +221,41 @@ abstract class AbstractBootArchiveIntegrationTests {
|
||||
}
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void testAndDevelopmentOnlyDependenciesAreNotIncludedInTheArchiveByDefault() throws IOException {
|
||||
File srcMainResources = new File(this.gradleBuild.getProjectDir(), "src/main/resources");
|
||||
srcMainResources.mkdirs();
|
||||
new File(srcMainResources, "resource").createNewFile();
|
||||
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName).getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
try (JarFile jarFile = new JarFile(new File(this.gradleBuild.getProjectDir(), "build/libs").listFiles()[0])) {
|
||||
Stream<String> libEntryNames = jarFile.stream()
|
||||
.filter((entry) -> !entry.isDirectory())
|
||||
.map(JarEntry::getName)
|
||||
.filter((name) -> name.startsWith(this.libPath));
|
||||
assertThat(libEntryNames).containsExactly(this.libPath + "commons-io-2.6.jar");
|
||||
Stream<String> classesEntryNames = jarFile.stream()
|
||||
.filter((entry) -> !entry.isDirectory())
|
||||
.map(JarEntry::getName)
|
||||
.filter((name) -> name.startsWith(this.classesPath));
|
||||
assertThat(classesEntryNames).containsExactly(this.classesPath + "resource");
|
||||
}
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void testAndDevelopmentOnlyDependenciesCanBeIncludedInTheArchive() throws IOException {
|
||||
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName).getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
try (JarFile jarFile = new JarFile(new File(this.gradleBuild.getProjectDir(), "build/libs").listFiles()[0])) {
|
||||
Stream<String> libEntryNames = jarFile.stream()
|
||||
.filter((entry) -> !entry.isDirectory())
|
||||
.map(JarEntry::getName)
|
||||
.filter((name) -> name.startsWith(this.libPath));
|
||||
assertThat(libEntryNames).containsExactly(this.libPath + "commons-io-2.6.jar",
|
||||
this.libPath + "commons-lang3-3.9.jar");
|
||||
}
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void jarTypeFilteringIsApplied() throws IOException {
|
||||
File flatDirRepository = new File(this.gradleBuild.getProjectDir(), "repository");
|
||||
|
||||
@@ -146,6 +146,22 @@ class BootRunIntegrationTests {
|
||||
assertThat(result.getOutput()).contains("com.example.bootrun.main.CustomMainClass");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void developmentOnlyDependenciesAreOnTheClasspath() throws IOException {
|
||||
copyClasspathApplication();
|
||||
BuildResult result = this.gradleBuild.build("bootRun");
|
||||
assertThat(result.task(":bootRun").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(result.getOutput()).contains("commons-lang3-3.12.0.jar");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void testAndDevelopmentOnlyDependenciesAreOnTheClasspath() throws IOException {
|
||||
copyClasspathApplication();
|
||||
BuildResult result = this.gradleBuild.build("bootRun");
|
||||
assertThat(result.task(":bootRun").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(result.getOutput()).contains("commons-lang3-3.12.0.jar");
|
||||
}
|
||||
|
||||
private void copyMainClassApplication() throws IOException {
|
||||
copyApplication("main");
|
||||
}
|
||||
|
||||
@@ -117,6 +117,22 @@ class BootTestRunIntegrationTests {
|
||||
}
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void developmentOnlyDependenciesAreNotOnTheClasspath() throws IOException {
|
||||
copyClasspathApplication();
|
||||
BuildResult result = this.gradleBuild.build("bootTestRun");
|
||||
assertThat(result.task(":bootTestRun").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(result.getOutput()).doesNotContain("commons-lang3-3.12.0.jar");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void testAndDevelopmentOnlyDependenciesAreOnTheClasspath() throws IOException {
|
||||
copyClasspathApplication();
|
||||
BuildResult result = this.gradleBuild.build("bootTestRun");
|
||||
assertThat(result.task(":bootTestRun").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(result.getOutput()).contains("commons-lang3-3.12.0.jar");
|
||||
}
|
||||
|
||||
private void copyClasspathApplication() throws IOException {
|
||||
copyApplication("classpath");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user