Polish Gradle layer configuration DSL
This commit modifies the DSL for custom layer configuration in the Gradle plugin to avoid duplication of terms that could be confusing. Fixes gh-20563
This commit is contained in:
parent
06cefabb5b
commit
e607c6842f
|
@ -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 {
|
||||
|
|
|
@ -8,8 +8,7 @@ plugins {
|
|||
// tag::layered[]
|
||||
tasks.getByName<BootJar>("bootJar") {
|
||||
layers {
|
||||
includeLayerTools = false
|
||||
layers("dependencies", "snapshot-dependencies", "resources", "application")
|
||||
layersOrder("dependencies", "snapshot-dependencies", "resources", "application")
|
||||
libraries {
|
||||
layerContent("snapshot-dependencies") {
|
||||
coordinates {
|
||||
|
|
|
@ -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<Layer> customLayers = this.layerConfiguration.getLayers().stream().map(Layer::new)
|
||||
List<Layer> customLayers = this.layerConfiguration.getLayersOrder().stream().map(Layer::new)
|
||||
.collect(Collectors.toList());
|
||||
this.layers = new CustomLayers(customLayers, this.layerConfiguration.getClasses(),
|
||||
this.layerConfiguration.getLibraries());
|
||||
|
|
|
@ -44,7 +44,7 @@ public class LayerConfiguration {
|
|||
|
||||
private boolean includeLayerTools = true;
|
||||
|
||||
private List<String> layerNames = new ArrayList<>();
|
||||
private List<String> layersOrder = new ArrayList<>();
|
||||
|
||||
private List<ResourceStrategy> resourceStrategies = new ArrayList<>();
|
||||
|
||||
|
@ -66,16 +66,16 @@ public class LayerConfiguration {
|
|||
}
|
||||
|
||||
@Input
|
||||
public List<String> getLayers() {
|
||||
return this.layerNames;
|
||||
public List<String> 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<String> layers) {
|
||||
this.layerNames = layers;
|
||||
public void layersOrder(List<String> 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<LayerConfiguration> 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<LayerConfiguration> 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<LayerConfiguration> config) {
|
||||
this.strategySpec.newStrategy();
|
||||
config.execute(this);
|
||||
|
|
|
@ -122,7 +122,7 @@ class BootJarTests extends AbstractBootArchiveTests<BootJar> {
|
|||
@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", "*:*"));
|
||||
|
|
|
@ -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:*" } }
|
||||
|
|
Loading…
Reference in New Issue