10
10
11
11
import org .gradle .api .DefaultTask ;
12
12
import org .gradle .api .artifacts .Configuration ;
13
+ import org .gradle .api .artifacts .FileCollectionDependency ;
14
+ import org .gradle .api .artifacts .component .ModuleComponentIdentifier ;
13
15
import org .gradle .api .file .FileCollection ;
14
16
import org .gradle .api .model .ObjectFactory ;
17
+ import org .gradle .api .provider .ProviderFactory ;
15
18
import org .gradle .api .tasks .InputFiles ;
16
19
import org .gradle .api .tasks .TaskAction ;
17
20
import org .gradle .internal .deprecation .DeprecatableConfiguration ;
21
24
22
25
import javax .inject .Inject ;
23
26
24
- import static org .elasticsearch .gradle .DistributionDownloadPlugin .DISTRO_EXTRACTED_CONFIG_PREFIX ;
25
-
26
27
public class ResolveAllDependencies extends DefaultTask {
27
28
28
29
private final ObjectFactory objectFactory ;
30
+ private final ProviderFactory providerFactory ;
29
31
30
32
Collection <Configuration > configs ;
31
33
32
34
@ Inject
33
- public ResolveAllDependencies (ObjectFactory objectFactory ) {
35
+ public ResolveAllDependencies (ObjectFactory objectFactory , ProviderFactory providerFactory ) {
34
36
this .objectFactory = objectFactory ;
37
+ this .providerFactory = providerFactory ;
35
38
}
36
39
37
40
@ InputFiles
38
41
public FileCollection getResolvedArtifacts () {
39
- return objectFactory .fileCollection ()
40
- .from (configs .stream ().filter (ResolveAllDependencies ::canBeResolved ).collect (Collectors .toList ()));
42
+ return objectFactory .fileCollection ().from (configs .stream ().filter (ResolveAllDependencies ::canBeResolved ).map (c -> {
43
+ // Make a copy of the configuration, omitting file collection dependencies to avoid building project artifacts
44
+ Configuration copy = c .copyRecursive (d -> d instanceof FileCollectionDependency == false );
45
+ copy .setCanBeConsumed (false );
46
+ return copy ;
47
+ })
48
+ // Include only module dependencies, ignoring things like project dependencies so we don't unnecessarily build stuff
49
+ .map (c -> c .getIncoming ().artifactView (v -> v .lenient (true ).componentFilter (i -> i instanceof ModuleComponentIdentifier )))
50
+ .map (artifactView -> providerFactory .provider (artifactView ::getFiles ))
51
+ .collect (Collectors .toList ()));
41
52
}
42
53
43
54
@ TaskAction
@@ -55,6 +66,7 @@ private static boolean canBeResolved(Configuration configuration) {
55
66
return false ;
56
67
}
57
68
}
58
- return configuration .getName ().startsWith (DISTRO_EXTRACTED_CONFIG_PREFIX ) == false ;
69
+
70
+ return true ;
59
71
}
60
72
}
0 commit comments