Stop developmentOnly from removing too much from executable jars and wars

Fixes gh-21288
This commit is contained in:
Andy Wilkinson
2020-05-04 15:59:44 +01:00
parent 66e8968b98
commit 1bc41ec336
8 changed files with 37 additions and 10 deletions

View File

@@ -46,11 +46,14 @@ abstract class AbstractBootArchiveIntegrationTests {
private final String libPath;
private final String classesPath;
GradleBuild gradleBuild;
protected AbstractBootArchiveIntegrationTests(String taskName, String libPath) {
protected AbstractBootArchiveIntegrationTests(String taskName, String libPath, String classesPath) {
this.taskName = taskName;
this.libPath = libPath;
this.classesPath = classesPath;
}
@TestTemplate
@@ -142,12 +145,18 @@ abstract class AbstractBootArchiveIntegrationTests {
@TestTemplate
void developmentOnlyDependenciesAreNotIncludedInTheArchiveByDefault() 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");
}
}

View File

@@ -58,7 +58,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class BootJarIntegrationTests extends AbstractBootArchiveIntegrationTests {
BootJarIntegrationTests() {
super("bootJar", "BOOT-INF/lib/");
super("bootJar", "BOOT-INF/lib/", "BOOT-INF/classes/");
}
@TestTemplate

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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.
@@ -24,7 +24,7 @@ package org.springframework.boot.gradle.tasks.bundling;
class BootWarIntegrationTests extends AbstractBootArchiveIntegrationTests {
BootWarIntegrationTests() {
super("bootWar", "WEB-INF/lib/");
super("bootWar", "WEB-INF/lib/", "WEB-INF/classes/");
}
}