17
17
package org .springframework .boot .gradle .tasks .bundling ;
18
18
19
19
import java .io .File ;
20
- import java .util .Arrays ;
21
- import java .util .Collections ;
22
20
import java .util .HashSet ;
23
21
import java .util .LinkedHashMap ;
24
22
import java .util .Map ;
30
28
import org .gradle .api .artifacts .ResolvedConfiguration ;
31
29
import org .gradle .api .file .FileCopyDetails ;
32
30
import org .gradle .api .specs .Spec ;
31
+ import org .gradle .api .tasks .SourceSet ;
33
32
34
33
import org .springframework .boot .loader .tools .Layer ;
35
34
import org .springframework .boot .loader .tools .Library ;
@@ -53,9 +52,9 @@ class LayerResolver {
53
52
54
53
private final Spec <FileCopyDetails > librarySpec ;
55
54
56
- LayerResolver (Iterable <Configuration > configurations , LayeredSpec layeredConfiguration ,
57
- Spec <FileCopyDetails > librarySpec ) {
58
- this .resolvedDependencies = new ResolvedDependencies (configurations );
55
+ LayerResolver (Iterable <SourceSet > sourceSets , Iterable < Configuration > configurations ,
56
+ LayeredSpec layeredConfiguration , Spec <FileCopyDetails > librarySpec ) {
57
+ this .resolvedDependencies = new ResolvedDependencies (sourceSets , configurations );
59
58
this .layeredConfiguration = layeredConfiguration ;
60
59
this .librarySpec = librarySpec ;
61
60
}
@@ -96,19 +95,41 @@ private Library asLibrary(FileCopyDetails details) {
96
95
*/
97
96
private static class ResolvedDependencies {
98
97
99
- private static final Set <String > DEPRECATED_FOR_RESOLUTION_CONFIGURATIONS = Collections
100
- .unmodifiableSet (new HashSet <>(Arrays .asList ("archives" , "compile" , "compileOnly" , "default" , "runtime" ,
101
- "testCompile" , "testCompileOnly" , "testRuntime" )));
98
+ private final Set <String > deprecatedForResolutionConfigurationNames ;
102
99
103
100
private final Map <Configuration , ResolvedConfigurationDependencies > configurationDependencies = new LinkedHashMap <>();
104
101
105
- ResolvedDependencies (Iterable <Configuration > configurations ) {
102
+ ResolvedDependencies (Iterable <SourceSet > sourceSets , Iterable <Configuration > configurations ) {
103
+ this .deprecatedForResolutionConfigurationNames = deprecatedForResolutionConfigurationNames (sourceSets );
106
104
configurations .forEach (this ::processConfiguration );
107
105
}
108
106
107
+ @ SuppressWarnings ("deprecation" )
108
+ private Set <String > deprecatedForResolutionConfigurationNames (Iterable <SourceSet > sourceSets ) {
109
+ Set <String > configurationNames = new HashSet <>();
110
+ configurationNames .add ("archives" );
111
+ configurationNames .add ("default" );
112
+ for (SourceSet sourceSet : sourceSets ) {
113
+ try {
114
+ configurationNames .add (sourceSet .getCompileConfigurationName ());
115
+ }
116
+ catch (NoSuchMethodError ex ) {
117
+ // Continue
118
+ }
119
+ configurationNames .add (sourceSet .getCompileOnlyConfigurationName ());
120
+ try {
121
+ configurationNames .add (sourceSet .getRuntimeConfigurationName ());
122
+ }
123
+ catch (NoSuchMethodError ex ) {
124
+ // Continue
125
+ }
126
+ }
127
+ return configurationNames ;
128
+ }
129
+
109
130
private void processConfiguration (Configuration configuration ) {
110
131
if (configuration .isCanBeResolved ()
111
- && !DEPRECATED_FOR_RESOLUTION_CONFIGURATIONS .contains (configuration .getName ())) {
132
+ && !this . deprecatedForResolutionConfigurationNames .contains (configuration .getName ())) {
112
133
this .configurationDependencies .put (configuration ,
113
134
new ResolvedConfigurationDependencies (configuration .getResolvedConfiguration ()));
114
135
}
0 commit comments