You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Put project deps in app layer and make customization easier
Previously, when building a layered jar with Gradle, project
dependencies were treated the same as any other dependency, being
included in the dependencies or snapshot dependencies layer based
on their version.
This commit updates the default layering when using Gradle to include
project dependencies in the application layer by default. The DSL has
also been updated to allow their layer to be customized using new
includeProjectDependencies() and excludeProjectDependencies() methods
rather than relying on including and excluding them via a
group:artifact:version pattern.
Closesgh-23431
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/asciidoc/packaging.adoc
+7-5
Original file line number
Diff line number
Diff line change
@@ -282,10 +282,10 @@ Layered jars use the same layout as regular boot packaged jars, but include an a
282
282
283
283
By default, the following layers are defined:
284
284
285
-
* `dependencies` for any dependency whose version does not contain `SNAPSHOT`.
285
+
* `dependencies` for any non-project dependency whose version does not contain `SNAPSHOT`.
286
286
* `spring-boot-loader` for the jar loader classes.
287
-
* `snapshot-dependencies` for any dependency whose version contains `SNAPSHOT`.
288
-
* `application` for application classes and resources.
287
+
* `snapshot-dependencies` for any non-project dependency whose version contains `SNAPSHOT`.
288
+
* `application` for project dependencies, application classes, and resources.
289
289
290
290
The layers order is important as it determines how likely previous layers can be cached when part of the application changes.
291
291
The default order is `dependencies`, `spring-boot-loader`, `snapshot-dependencies`, `application`.
@@ -355,13 +355,15 @@ Any content not claimed by an earlier `intoLayer` closure remains available for
355
355
The `intoLayer` closure claims content using nested `include` and `exclude` calls.
356
356
The `application` closure uses Ant-style patch matching for include/exclude parameters.
357
357
The `dependencies` section uses `group:artifact[:version]` patterns.
358
+
It also provides `includeProjectDependencies()` and `excludeProjectDependencies()` methods that can be used to include or exclude project dependencies.
358
359
359
360
If no `include` call is made, then all content (not claimed by an earlier closure) is considered.
360
361
361
362
If no `exclude` call is made, then no exclusions are applied.
362
363
363
-
Looking at the `dependencies` closure in the example above, we can see that the first `intoLayer` will claim all SNAPSHOT dependencies for the `snapshot-dependencies` layer.
364
-
The subsequent `intoLayer` will claim anything left (in this case, any dependency that is not a SNAPSHOT) for the `dependencies` layer.
364
+
Looking at the `dependencies` closure in the example above, we can see that the first `intoLayer` will claim all project dependencies for the `application` layer.
365
+
The next `intoLayer` will claim all SNAPSHOT dependencies for the `snapshot-dependencies` layer.
366
+
The third and final `intoLayer` will claim anything left (in this case, any dependency that is not a project dependency or a SNAPSHOT) for the `dependencies` layer.
365
367
366
368
The `application` closure has similar rules.
367
369
First claiming `org/springframework/boot/loader/**` content for the `spring-boot-loader` layer.
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/docs/gradle/packaging/boot-jar-layered-custom.gradle
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/LayerResolver.java
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/LayeredSpec.java
+106-15
Original file line number
Diff line number
Diff line change
@@ -227,31 +227,33 @@ public abstract static class IntoLayersSpec implements Serializable {
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/ResolvedDependencies.java
0 commit comments