Allow users to opt out of including the layer tools in a layered jar
For Maven, the layer configuration is now an additional configuration option instead of a layout type. Closes gh-19866
This commit is contained in:
@@ -29,6 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* Integration tests for {@link BootJar}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Madhura Bhave
|
||||
*/
|
||||
class BootJarIntegrationTests extends AbstractBootArchiveIntegrationTests {
|
||||
|
||||
@@ -53,4 +54,13 @@ class BootJarIntegrationTests extends AbstractBootArchiveIntegrationTests {
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void notUpToDateWhenBuiltWithLayersAndToolsAndThenWithLayersAndWithoutTools()
|
||||
throws InvalidRunnerConfigurationException, UnexpectedBuildFailure, IOException {
|
||||
assertThat(this.gradleBuild.build("-Playered=true", "bootJar").task(":bootJar").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("-Playered=true", "-PexcludeTools=true", "bootJar").task(":bootJar")
|
||||
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.util.jar.JarFile;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
import org.gradle.api.Action;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -129,6 +130,13 @@ class BootJarTests extends AbstractBootArchiveTests<BootJar> {
|
||||
assertThat(entryNames).contains("BOOT-INF/layers/dependencies/lib/spring-boot-jarmode-layertools.jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenJarIsLayeredAndIncludeLayerToolsIsFalseThenLayerToolsAreNotAddedToTheJar() throws IOException {
|
||||
List<String> entryNames = getEntryNames(
|
||||
createLayeredJar((configuration) -> configuration.setIncludeLayerTools(false)));
|
||||
assertThat(entryNames).doesNotContain("BOOT-INF/layers/dependencies/lib/spring-boot-jarmode-layertools.jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
void classpathIndexPointsToBootInfLibs() throws IOException {
|
||||
try (JarFile jarFile = new JarFile(createPopulatedJar())) {
|
||||
@@ -145,13 +153,22 @@ class BootJarTests extends AbstractBootArchiveTests<BootJar> {
|
||||
return getTask().getArchiveFile().get().getAsFile();
|
||||
}
|
||||
|
||||
private File createLayeredJar() throws IOException {
|
||||
private File createLayeredJar(Action<LayerConfiguration> action) throws IOException {
|
||||
addContent();
|
||||
getTask().layered();
|
||||
if (action != null) {
|
||||
getTask().layered(action);
|
||||
}
|
||||
else {
|
||||
getTask().layered();
|
||||
}
|
||||
executeTask();
|
||||
return getTask().getArchiveFile().get().getAsFile();
|
||||
}
|
||||
|
||||
private File createLayeredJar() throws IOException {
|
||||
return createLayeredJar(null);
|
||||
}
|
||||
|
||||
private void addContent() throws IOException {
|
||||
BootJar bootJar = getTask();
|
||||
bootJar.setMainClassName("com.example.Main");
|
||||
|
||||
Reference in New Issue
Block a user