diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/packaging/boot-jar-layered-custom.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/packaging/boot-jar-layered-custom.gradle index 8e802ced8e..23e203b184 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/packaging/boot-jar-layered-custom.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/packaging/boot-jar-layered-custom.gradle @@ -10,7 +10,7 @@ bootJar { // tag::layered[] bootJar { layers { - layers "dependencies", "snapshot-dependencies", "resources", "application" + layersOrder "dependencies", "snapshot-dependencies", "resources", "application" libraries { layerContent("snapshot-dependencies") { coordinates { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/packaging/boot-jar-layered-custom.gradle.kts b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/packaging/boot-jar-layered-custom.gradle.kts index d0b5d4ffb3..b9c7d200ef 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/packaging/boot-jar-layered-custom.gradle.kts +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/packaging/boot-jar-layered-custom.gradle.kts @@ -8,8 +8,7 @@ plugins { // tag::layered[] tasks.getByName("bootJar") { layers { - includeLayerTools = false - layers("dependencies", "snapshot-dependencies", "resources", "application") + layersOrder("dependencies", "snapshot-dependencies", "resources", "application") libraries { layerContent("snapshot-dependencies") { coordinates { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootJar.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootJar.java index 5e5ebd4d1b..baf8ba7fd0 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootJar.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootJar.java @@ -208,11 +208,11 @@ public class BootJar extends Jar implements BootArchive { return; } - if (this.layerConfiguration.getLayers() == null || this.layerConfiguration.getLayers().isEmpty()) { + if (this.layerConfiguration.getLayersOrder() == null || this.layerConfiguration.getLayersOrder().isEmpty()) { this.layers = Layers.IMPLICIT; } else { - List customLayers = this.layerConfiguration.getLayers().stream().map(Layer::new) + List customLayers = this.layerConfiguration.getLayersOrder().stream().map(Layer::new) .collect(Collectors.toList()); this.layers = new CustomLayers(customLayers, this.layerConfiguration.getClasses(), this.layerConfiguration.getLibraries()); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/LayerConfiguration.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/LayerConfiguration.java index efdabf8a2c..6adcbc9baa 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/LayerConfiguration.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/LayerConfiguration.java @@ -44,7 +44,7 @@ public class LayerConfiguration { private boolean includeLayerTools = true; - private List layerNames = new ArrayList<>(); + private List layersOrder = new ArrayList<>(); private List resourceStrategies = new ArrayList<>(); @@ -66,16 +66,16 @@ public class LayerConfiguration { } @Input - public List getLayers() { - return this.layerNames; + public List getLayersOrder() { + return this.layersOrder; } - public void layers(String... layers) { - this.layerNames = Arrays.asList(layers); + public void layersOrder(String... layers) { + this.layersOrder = Arrays.asList(layers); } - public void layers(List layers) { - this.layerNames = layers; + public void layersOrder(List layers) { + this.layersOrder = layers; } @Input @@ -84,10 +84,12 @@ public class LayerConfiguration { } public void classes(ResourceStrategy... resourceStrategies) { + assertLayersOrderConfigured(); this.resourceStrategies = Arrays.asList(resourceStrategies); } public void classes(Action config) { + assertLayersOrderConfigured(); this.strategySpec = StrategySpec.forResources(); config.execute(this); } @@ -98,14 +100,20 @@ public class LayerConfiguration { } public void libraries(LibraryStrategy... strategies) { + assertLayersOrderConfigured(); this.libraryStrategies = Arrays.asList(strategies); } public void libraries(Action configure) { + assertLayersOrderConfigured(); this.strategySpec = StrategySpec.forLibraries(); configure.execute(this); } + private void assertLayersOrderConfigured() { + Assert.state(!this.layersOrder.isEmpty(), "'layersOrder' must be configured before filters can be applied."); + } + public void layerContent(String layerName, Action config) { this.strategySpec.newStrategy(); config.execute(this); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarTests.java index 2b585f2bce..c6be4244ab 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarTests.java @@ -122,7 +122,7 @@ class BootJarTests extends AbstractBootArchiveTests { @Test void whenJarIsLayeredWithCustomStrategiesThenContentsAreMovedToLayerDirectories() throws IOException { File jar = createLayeredJar((configuration) -> { - configuration.layers("my-deps", "my-internal-deps", "my-snapshot-deps", "resources", "application"); + configuration.layersOrder("my-deps", "my-internal-deps", "my-snapshot-deps", "resources", "application"); configuration.libraries(createLibraryStrategy("my-snapshot-deps", "com.example:*:*.SNAPSHOT"), createLibraryStrategy("my-internal-deps", "com.example:*:*"), createLibraryStrategy("my-deps", "*:*")); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-customLayers.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-customLayers.gradle index 92adc33456..42353c3ea9 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-customLayers.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-customLayers.gradle @@ -6,7 +6,7 @@ plugins { bootJar { mainClassName = 'com.example.Application' layers { - layers "dependencies", "commons-dependencies", "snapshot-dependencies", "static", "app" + layersOrder "dependencies", "commons-dependencies", "snapshot-dependencies", "static", "app" libraries { layerContent("snapshot-dependencies") { coordinates { include "*:*:*SNAPSHOT" } } layerContent("commons-dependencies") { coordinates { include "org.apache.commons:*" } }