Skip to content

Commit 283f1b1

Browse files
committed
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 (4f677be) 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 (38585bf) 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 spring-projects#672
1 parent fb29a3c commit 283f1b1

File tree

1 file changed

+24
-27
lines changed
  • spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/task

1 file changed

+24
-27
lines changed

spring-boot-tools/spring-boot-gradle-plugin/src/main/groovy/org/springframework/boot/gradle/task/ProjectLibraries.java

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616

1717
package org.springframework.boot.gradle.task;
1818

19+
import java.io.File;
1920
import java.io.IOException;
2021
import java.util.Collections;
2122
import java.util.Set;
2223

2324
import org.gradle.api.Project;
2425
import org.gradle.api.artifacts.Configuration;
25-
import org.gradle.api.artifacts.ResolvedArtifact;
26+
import org.gradle.api.file.FileCollection;
2627
import org.springframework.boot.loader.tools.Libraries;
2728
import org.springframework.boot.loader.tools.LibraryCallback;
2829
import org.springframework.boot.loader.tools.LibraryScope;
@@ -66,44 +67,40 @@ public void setCustomConfigurationName(String customConfigurationName) {
6667
@Override
6768
public void doWithLibraries(LibraryCallback callback) throws IOException {
6869

69-
Configuration custom = this.customConfigurationName != null ? this.project
70+
FileCollection custom = this.customConfigurationName != null ? this.project
7071
.getConfigurations().findByName(this.customConfigurationName) : null;
7172

7273
if (custom != null) {
73-
libraries(LibraryScope.CUSTOM, getResolvedArtifacts(custom), callback);
74+
libraries(LibraryScope.CUSTOM, custom, callback);
7475
}
7576
else {
76-
Set<ResolvedArtifact> compileArtifacts = getResolvedArtifacts("compile");
77-
Set<ResolvedArtifact> runtimeArtifacts = getResolvedArtifacts("runtime");
78-
runtimeArtifacts.removeAll(compileArtifacts);
77+
FileCollection compile = this.project.getConfigurations()
78+
.getByName("compile");
7979

80-
Set<ResolvedArtifact> providedArtifacts = getResolvedArtifacts(this.providedConfigurationName);
81-
compileArtifacts.removeAll(providedArtifacts);
82-
runtimeArtifacts.removeAll(providedArtifacts);
80+
FileCollection runtime = this.project.getConfigurations()
81+
.getByName("runtime");
82+
runtime = runtime.minus(compile);
8383

84-
libraries(LibraryScope.COMPILE, compileArtifacts, callback);
85-
libraries(LibraryScope.RUNTIME, runtimeArtifacts, callback);
86-
libraries(LibraryScope.PROVIDED, providedArtifacts, callback);
87-
}
88-
}
84+
FileCollection provided = this.project.getConfigurations()
85+
.findByName(this.providedConfigurationName);
8986

90-
private Set<ResolvedArtifact> getResolvedArtifacts(Configuration configuration) {
91-
if (configuration == null) {
92-
return Collections.emptySet();
93-
}
94-
return configuration.getResolvedConfiguration().getResolvedArtifacts();
95-
}
87+
if (provided != null) {
88+
compile = compile.minus(provided);
89+
runtime = runtime.minus(provided);
90+
}
9691

97-
private Set<ResolvedArtifact> getResolvedArtifacts(String configurationName) {
98-
Configuration configuration = this.project.getConfigurations().findByName(
99-
configurationName);
100-
return getResolvedArtifacts(configuration);
92+
libraries(LibraryScope.COMPILE, compile, callback);
93+
libraries(LibraryScope.RUNTIME, runtime, callback);
94+
libraries(LibraryScope.PROVIDED, provided, callback);
95+
}
10196
}
10297

103-
private void libraries(LibraryScope scope, Set<ResolvedArtifact> artifacts,
98+
private void libraries(LibraryScope scope, FileCollection files,
10499
LibraryCallback callback) throws IOException {
105-
for (ResolvedArtifact artifact : artifacts) {
106-
callback.library(artifact.getFile(), scope);
100+
if (files != null) {
101+
for (File file: files) {
102+
callback.library(file, scope);
103+
}
107104
}
108105
}
109106
}

0 commit comments

Comments
 (0)