1111import org .elasticsearch .gradle .VersionProperties ;
1212import org .gradle .api .DefaultTask ;
1313import org .gradle .api .artifacts .Configuration ;
14+ import org .gradle .api .artifacts .FileCollectionDependency ;
15+ import org .gradle .api .artifacts .component .ModuleComponentIdentifier ;
1416import org .gradle .api .file .FileCollection ;
1517import org .gradle .api .model .ObjectFactory ;
18+ import org .gradle .api .provider .ProviderFactory ;
1619import org .gradle .api .tasks .InputFiles ;
1720import org .gradle .api .tasks .Internal ;
1821import org .gradle .api .tasks .TaskAction ;
2528
2629import javax .inject .Inject ;
2730
28- import static org .elasticsearch .gradle .DistributionDownloadPlugin .DISTRO_EXTRACTED_CONFIG_PREFIX ;
29- import static org .elasticsearch .gradle .internal .test .rest .compat .compat .LegacyYamlRestCompatTestPlugin .BWC_MINOR_CONFIG_NAME ;
30-
3131public abstract class ResolveAllDependencies extends DefaultTask {
3232
3333 private boolean resolveJavaToolChain = false ;
@@ -36,18 +36,28 @@ public abstract class ResolveAllDependencies extends DefaultTask {
3636 protected abstract JavaToolchainService getJavaToolchainService ();
3737
3838 private final ObjectFactory objectFactory ;
39+ private final ProviderFactory providerFactory ;
3940
4041 private Collection <Configuration > configs ;
4142
4243 @ Inject
43- public ResolveAllDependencies (ObjectFactory objectFactory ) {
44+ public ResolveAllDependencies (ObjectFactory objectFactory , ProviderFactory providerFactory ) {
4445 this .objectFactory = objectFactory ;
46+ this .providerFactory = providerFactory ;
4547 }
4648
4749 @ InputFiles
4850 public FileCollection getResolvedArtifacts () {
49- return objectFactory .fileCollection ()
50- .from (configs .stream ().filter (ResolveAllDependencies ::canBeResolved ).collect (Collectors .toList ()));
51+ return objectFactory .fileCollection ().from (configs .stream ().filter (ResolveAllDependencies ::canBeResolved ).map (c -> {
52+ // Make a copy of the configuration, omitting file collection dependencies to avoid building project artifacts
53+ Configuration copy = c .copyRecursive (d -> d instanceof FileCollectionDependency == false );
54+ copy .setCanBeConsumed (false );
55+ return copy ;
56+ })
57+ // Include only module dependencies, ignoring things like project dependencies so we don't unnecessarily build stuff
58+ .map (c -> c .getIncoming ().artifactView (v -> v .lenient (true ).componentFilter (i -> i instanceof ModuleComponentIdentifier )))
59+ .map (artifactView -> providerFactory .provider (artifactView ::getFiles ))
60+ .collect (Collectors .toList ()));
5161 }
5262
5363 @ TaskAction
@@ -94,8 +104,8 @@ private static boolean canBeResolved(Configuration configuration) {
94104 return false ;
95105 }
96106 }
97- return configuration . getName (). startsWith ( DISTRO_EXTRACTED_CONFIG_PREFIX ) == false
98- && configuration . getName (). equals ( BWC_MINOR_CONFIG_NAME ) == false ;
107+
108+ return true ;
99109 }
100110
101111}
0 commit comments