From 283f1b169f7302703e4605b8acc2924e28b1bf8a Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 15 Apr 2014 15:44:40 +0100 Subject: [PATCH] Ensure that local file dependencies are packaged by the Gradle plugin Prior to this commit, a dependency on a local file was not being packaged by the Gradle plugin. This was a regression from the behaviour in 0.5.0.M6 caused by the move to using a ResolvedConfiguration and ResolvedArtifacts (4f677bec) to gain access to an artifact's type so that non-jar artefacts could be filtered out. Since then, the approach to filtering has been changed (38585bf3) and access to an artifact's type is no longer needed. This commit updates ProjectLibraries to restore its use of a FileCollection rather than a ResolvedConfiguration when getting hold of the files in a configuration. This means that the resulting jar will now include dependencies that aren't resolved, such as those that are provided as local files. The filtering that is applied to the files is unaffected by this change and only files that are zip files will be included. Fixes #672 --- .../boot/gradle/task/ProjectLibraries.java | 53 +++++++++---------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/task/ProjectLibraries.java b/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/task/ProjectLibraries.java index 3197b21b6e..105fa7dcd1 100644 --- a/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/task/ProjectLibraries.java +++ b/spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/task/ProjectLibraries.java @@ -16,13 +16,14 @@ package org.springframework.boot.gradle.task; +import java.io.File; import java.io.IOException; import java.util.Collections; import java.util.Set; import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; -import org.gradle.api.artifacts.ResolvedArtifact; +import org.gradle.api.file.FileCollection; import org.springframework.boot.loader.tools.Libraries; import org.springframework.boot.loader.tools.LibraryCallback; import org.springframework.boot.loader.tools.LibraryScope; @@ -66,44 +67,40 @@ class ProjectLibraries implements Libraries { @Override public void doWithLibraries(LibraryCallback callback) throws IOException { - Configuration custom = this.customConfigurationName != null ? this.project + FileCollection custom = this.customConfigurationName != null ? this.project .getConfigurations().findByName(this.customConfigurationName) : null; if (custom != null) { - libraries(LibraryScope.CUSTOM, getResolvedArtifacts(custom), callback); + libraries(LibraryScope.CUSTOM, custom, callback); } else { - Set compileArtifacts = getResolvedArtifacts("compile"); - Set runtimeArtifacts = getResolvedArtifacts("runtime"); - runtimeArtifacts.removeAll(compileArtifacts); + FileCollection compile = this.project.getConfigurations() + .getByName("compile"); - Set providedArtifacts = getResolvedArtifacts(this.providedConfigurationName); - compileArtifacts.removeAll(providedArtifacts); - runtimeArtifacts.removeAll(providedArtifacts); + FileCollection runtime = this.project.getConfigurations() + .getByName("runtime"); + runtime = runtime.minus(compile); - libraries(LibraryScope.COMPILE, compileArtifacts, callback); - libraries(LibraryScope.RUNTIME, runtimeArtifacts, callback); - libraries(LibraryScope.PROVIDED, providedArtifacts, callback); + FileCollection provided = this.project.getConfigurations() + .findByName(this.providedConfigurationName); + + if (provided != null) { + compile = compile.minus(provided); + runtime = runtime.minus(provided); + } + + libraries(LibraryScope.COMPILE, compile, callback); + libraries(LibraryScope.RUNTIME, runtime, callback); + libraries(LibraryScope.PROVIDED, provided, callback); } } - private Set getResolvedArtifacts(Configuration configuration) { - if (configuration == null) { - return Collections.emptySet(); - } - return configuration.getResolvedConfiguration().getResolvedArtifacts(); - } - - private Set getResolvedArtifacts(String configurationName) { - Configuration configuration = this.project.getConfigurations().findByName( - configurationName); - return getResolvedArtifacts(configuration); - } - - private void libraries(LibraryScope scope, Set artifacts, + private void libraries(LibraryScope scope, FileCollection files, LibraryCallback callback) throws IOException { - for (ResolvedArtifact artifact : artifacts) { - callback.library(artifact.getFile(), scope); + if (files != null) { + for (File file: files) { + callback.library(file, scope); + } } } }