1212import org .elasticsearch .gradle .VersionProperties ;
1313import org .gradle .api .DefaultTask ;
1414import org .gradle .api .artifacts .Configuration ;
15+ import org .gradle .api .artifacts .FileCollectionDependency ;
16+ import org .gradle .api .artifacts .component .ModuleComponentIdentifier ;
1517import org .gradle .api .file .FileCollection ;
1618import org .gradle .api .model .ObjectFactory ;
19+ import org .gradle .api .provider .ProviderFactory ;
1720import org .gradle .api .tasks .InputFiles ;
1821import org .gradle .api .tasks .Internal ;
1922import org .gradle .api .tasks .TaskAction ;
2629
2730import javax .inject .Inject ;
2831
29- import static org .elasticsearch .gradle .DistributionDownloadPlugin .DISTRO_EXTRACTED_CONFIG_PREFIX ;
30- import static org .elasticsearch .gradle .internal .test .rest .compat .compat .LegacyYamlRestCompatTestPlugin .BWC_MINOR_CONFIG_NAME ;
31-
3232public abstract class ResolveAllDependencies extends DefaultTask {
3333
3434 private boolean resolveJavaToolChain = false ;
@@ -37,18 +37,28 @@ public abstract class ResolveAllDependencies extends DefaultTask {
3737 protected abstract JavaToolchainService getJavaToolchainService ();
3838
3939 private final ObjectFactory objectFactory ;
40+ private final ProviderFactory providerFactory ;
4041
4142 private Collection <Configuration > configs ;
4243
4344 @ Inject
44- public ResolveAllDependencies (ObjectFactory objectFactory ) {
45+ public ResolveAllDependencies (ObjectFactory objectFactory , ProviderFactory providerFactory ) {
4546 this .objectFactory = objectFactory ;
47+ this .providerFactory = providerFactory ;
4648 }
4749
4850 @ InputFiles
4951 public FileCollection getResolvedArtifacts () {
50- return objectFactory .fileCollection ()
51- .from (configs .stream ().filter (ResolveAllDependencies ::canBeResolved ).collect (Collectors .toList ()));
52+ return objectFactory .fileCollection ().from (configs .stream ().filter (ResolveAllDependencies ::canBeResolved ).map (c -> {
53+ // Make a copy of the configuration, omitting file collection dependencies to avoid building project artifacts
54+ Configuration copy = c .copyRecursive (d -> d instanceof FileCollectionDependency == false );
55+ copy .setCanBeConsumed (false );
56+ return copy ;
57+ })
58+ // Include only module dependencies, ignoring things like project dependencies so we don't unnecessarily build stuff
59+ .map (c -> c .getIncoming ().artifactView (v -> v .lenient (true ).componentFilter (i -> i instanceof ModuleComponentIdentifier )))
60+ .map (artifactView -> providerFactory .provider (artifactView ::getFiles ))
61+ .collect (Collectors .toList ()));
5262 }
5363
5464 @ TaskAction
@@ -95,8 +105,8 @@ private static boolean canBeResolved(Configuration configuration) {
95105 return false ;
96106 }
97107 }
98- return configuration . getName (). startsWith ( DISTRO_EXTRACTED_CONFIG_PREFIX ) == false
99- && configuration . getName (). equals ( BWC_MINOR_CONFIG_NAME ) == false ;
108+
109+ return true ;
100110 }
101111
102112}
0 commit comments