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.

Closes gh-23431
This commit is contained in:
Andy Wilkinson
2020-10-15 12:19:18 +01:00
parent ad6ea94112
commit 84f96033c5
11 changed files with 292 additions and 35 deletions

View File

@@ -36,6 +36,9 @@ class ImplicitLayerResolver extends StandardLayers {
@Override
public Layer getLayer(Library library) {
if (library.isLocal()) {
return APPLICATION;
}
if (library.getName().contains("SNAPSHOT.")) {
return SNAPSHOT_DEPENDENCIES;
}

View File

@@ -41,6 +41,8 @@ public class Library {
private final boolean unpackRequired;
private final boolean local;
/**
* Create a new {@link Library}.
* @param file the source file
@@ -82,11 +84,29 @@ public class Library {
* @param unpackRequired if the library needs to be unpacked before it can be used
*/
public Library(String name, File file, LibraryScope scope, LibraryCoordinates coordinates, boolean unpackRequired) {
this(name, file, scope, coordinates, unpackRequired, false);
}
/**
* Create a new {@link Library}.
* @param name the name of the library as it should be written or {@code null} to use
* the file name
* @param file the source file
* @param scope the scope of the library
* @param coordinates the library coordinates or {@code null}
* @param unpackRequired if the library needs to be unpacked before it can be used
* @param local if the library is local (part of the same build) to the application
* that is being packaged
* @since 2.4.0
*/
public Library(String name, File file, LibraryScope scope, LibraryCoordinates coordinates, boolean unpackRequired,
boolean local) {
this.name = (name != null) ? name : file.getName();
this.file = file;
this.scope = scope;
this.coordinates = coordinates;
this.unpackRequired = unpackRequired;
this.local = local;
}
/**
@@ -143,4 +163,13 @@ public class Library {
return this.file.lastModified();
}
/**
* Return if the library is local (part of the same build) to the application that is
* being packaged.
* @return if the library is local
*/
public boolean isLocal() {
return this.local;
}
}