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
This commit is contained in:
Andy Wilkinson 2014-04-15 15:44:40 +01:00
parent fb29a3c318
commit 283f1b169f

View File

@ -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<ResolvedArtifact> compileArtifacts = getResolvedArtifacts("compile");
Set<ResolvedArtifact> runtimeArtifacts = getResolvedArtifacts("runtime");
runtimeArtifacts.removeAll(compileArtifacts);
FileCollection compile = this.project.getConfigurations()
.getByName("compile");
Set<ResolvedArtifact> 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<ResolvedArtifact> getResolvedArtifacts(Configuration configuration) {
if (configuration == null) {
return Collections.emptySet();
}
return configuration.getResolvedConfiguration().getResolvedArtifacts();
}
private Set<ResolvedArtifact> getResolvedArtifacts(String configurationName) {
Configuration configuration = this.project.getConfigurations().findByName(
configurationName);
return getResolvedArtifacts(configuration);
}
private void libraries(LibraryScope scope, Set<ResolvedArtifact> 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);
}
}
}
}