Consider transitives when identifying project dependencies
Previously, when building a layered jar, the Gradle plugin only considered a configuration's direct dependencies when identifying project dependencies. This resulted in transitive project dependencies being missed when deciding which dependencies belong in the application layer. This commit updates ResolvedDependencies to consider all projects from the root project when collecting the IDs of local projects. This ensures that any project dependency, no matter where it appears in the dependency graph, is successfully identified. Fixes gh-25163
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -74,15 +74,16 @@ public class BootJar extends Jar implements BootArchive {
|
||||
*/
|
||||
public BootJar() {
|
||||
this.support = new BootArchiveSupport(LAUNCHER, new LibrarySpec(), new ZipCompressionResolver());
|
||||
this.bootInfSpec = getProject().copySpec().into("BOOT-INF");
|
||||
this.mainClass = getProject().getObjects().property(String.class);
|
||||
Project project = getProject();
|
||||
this.bootInfSpec = project.copySpec().into("BOOT-INF");
|
||||
this.mainClass = project.getObjects().property(String.class);
|
||||
configureBootInfSpec(this.bootInfSpec);
|
||||
getMainSpec().with(this.bootInfSpec);
|
||||
getProject().getConfigurations().all((configuration) -> {
|
||||
project.getConfigurations().all((configuration) -> {
|
||||
ResolvableDependencies incoming = configuration.getIncoming();
|
||||
incoming.afterResolve((resolvableDependencies) -> {
|
||||
if (resolvableDependencies == incoming) {
|
||||
this.resolvedDependencies.processConfiguration(configuration);
|
||||
this.resolvedDependencies.processConfiguration(project, configuration);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,9 +22,9 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.artifacts.ModuleVersionIdentifier;
|
||||
import org.gradle.api.artifacts.ProjectDependency;
|
||||
import org.gradle.api.artifacts.ResolvedArtifact;
|
||||
import org.gradle.api.artifacts.ResolvedConfiguration;
|
||||
|
||||
@@ -44,13 +44,15 @@ class ResolvedDependencies {
|
||||
|
||||
private final Map<Configuration, ResolvedConfigurationDependencies> configurationDependencies = new LinkedHashMap<>();
|
||||
|
||||
void processConfiguration(Configuration configuration) {
|
||||
Set<String> projectDependencyIds = configuration.getAllDependencies().withType(ProjectDependency.class).stream()
|
||||
.map((projectDependency) -> projectDependency.getGroup() + ":" + projectDependency.getName() + ":"
|
||||
+ projectDependency.getVersion())
|
||||
private String projectId(Project project) {
|
||||
return project.getGroup() + ":" + project.getName() + ":" + project.getVersion();
|
||||
}
|
||||
|
||||
void processConfiguration(Project project, Configuration configuration) {
|
||||
Set<String> localProjectIds = project.getRootProject().getAllprojects().stream().map(this::projectId)
|
||||
.collect(Collectors.toSet());
|
||||
this.configurationDependencies.put(configuration,
|
||||
new ResolvedConfigurationDependencies(projectDependencyIds, configuration.getResolvedConfiguration()));
|
||||
new ResolvedConfigurationDependencies(localProjectIds, configuration.getResolvedConfiguration()));
|
||||
}
|
||||
|
||||
DependencyDescriptor find(File file) {
|
||||
|
||||
Reference in New Issue
Block a user