Include transitive file dependencies during Gradle repackaging

Previously, ProjectLibraries only considered a configuration's
direct file dependencies. This meant that a transitive file
dependency that should have been pulled in via a project dependency
was not included in the repackaged jar's lib directory.

ProjectLibraries has been updated to walk down the tree of project
dependencies and create libraries for any file dependencies that
are found.

Fixes gh-1368
This commit is contained in:
Andy Wilkinson
2014-08-20 14:19:57 +01:00
parent c7045f5294
commit 69c61d0e8e
6 changed files with 129 additions and 4 deletions

View File

@@ -27,6 +27,7 @@ import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.FileCollectionDependency;
import org.gradle.api.artifacts.ModuleVersionIdentifier;
import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.api.artifacts.ResolvedArtifact;
import org.springframework.boot.gradle.SpringBootPluginExtension;
import org.springframework.boot.loader.tools.Libraries;
@@ -109,6 +110,14 @@ class ProjectLibraries implements Libraries {
.getResolvedArtifacts()) {
libraries.add(new ResolvedArtifactLibrary(artifact, scope));
}
libraries.addAll(getLibrariesForFileDependencies(configuration, scope));
return libraries;
}
private Set<Library> getLibrariesForFileDependencies(Configuration configuration,
LibraryScope scope) {
Set<Library> libraries = new LinkedHashSet<Library>();
for (Dependency dependency : configuration.getIncoming().getDependencies()) {
if (dependency instanceof FileCollectionDependency) {
FileCollectionDependency fileDependency = (FileCollectionDependency) dependency;
@@ -116,6 +125,11 @@ class ProjectLibraries implements Libraries {
libraries.add(new Library(file, scope));
}
}
else if (dependency instanceof ProjectDependency) {
ProjectDependency projectDependency = (ProjectDependency) dependency;
libraries.addAll(getLibrariesForFileDependencies(
projectDependency.getProjectConfiguration(), scope));
}
}
return libraries;
}
@@ -161,7 +175,7 @@ class ProjectLibraries implements Libraries {
@Override
public boolean isUnpackRequired() {
if (ProjectLibraries.this.extension.getRequiresUnpack() != null) {
ModuleVersionIdentifier id = artifact.getModuleVersion().getId();
ModuleVersionIdentifier id = this.artifact.getModuleVersion().getId();
return ProjectLibraries.this.extension.getRequiresUnpack().contains(
id.getGroup() + ":" + id.getName());
}