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 6ad01f6d58..6ea136cadb 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 @@ -31,7 +31,6 @@ import org.gradle.api.plugins.JavaPluginConvention; import org.gradle.api.specs.Spec; import org.gradle.api.tasks.Internal; import org.gradle.api.tasks.Nested; -import org.gradle.api.tasks.Optional; import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.bundling.Jar; @@ -168,12 +167,11 @@ public class BootJar extends Jar implements BootArchive { } /** - * Returns the spec that describes the layers in a layerd jar. - * @return the spec for the layers or {@code null}. + * Returns the spec that describes the layers in a layered jar. + * @return the spec for the layers * @since 2.3.0 */ @Nested - @Optional public LayeredSpec getLayered() { return this.layered; } @@ -181,19 +179,19 @@ public class BootJar extends Jar implements BootArchive { /** * Configures the jar to be layered using the default layering. * @since 2.3.0 + * @deprecated since 2.4.0 as layering as now enabled by default. */ + @Deprecated public void layered() { - enableLayeringIfNecessary(); } /** - * Configures the jar to be layered, customizing the layers using the given - * {@code action}. + * Configures the jar's layering using the given {@code action}. * @param action the action to apply * @since 2.3.0 */ public void layered(Action action) { - action.execute(enableLayeringIfNecessary()); + action.execute(this.layered); } @Override @@ -290,13 +288,6 @@ public class BootJar extends Jar implements BootArchive { return launchScript; } - private LayeredSpec enableLayeringIfNecessary() { - if (this.layered == null) { - this.layered = new LayeredSpec(); - } - return this.layered; - } - /** * Syntactic sugar that makes {@link CopySpec#into} calls a little easier to read. * @param the result type 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 6f8a288f88..f06c46c02d 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 @@ -261,16 +261,12 @@ class BootJarTests extends AbstractBootArchiveTests { } private File createLayeredJar() throws IOException { - return createLayeredJar(null); + return createLayeredJar((spec) -> { + }); } private File createLayeredJar(Action action) throws IOException { - if (action != null) { - getTask().layered(action); - } - else { - getTask().layered(); - } + getTask().layered(action); addContent(); executeTask(); return getTask().getArchiveFile().get().getAsFile(); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-implicitLayers.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-implicitLayers.gradle index 3c2218ae4c..0be9a5be73 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-implicitLayers.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-implicitLayers.gradle @@ -5,7 +5,6 @@ plugins { bootJar { mainClassName = 'com.example.Application' - layered() } repositories { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-layersWithCustomSourceSet.gradle b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-layersWithCustomSourceSet.gradle index 2cbb899f1c..1db1c98abe 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-layersWithCustomSourceSet.gradle +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-layersWithCustomSourceSet.gradle @@ -9,7 +9,6 @@ sourceSets { bootJar { mainClassName = 'com.example.Application' - layered() } repositories {