From c657bfeb05f04ee74498b8f99e59867c378c857a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Fri, 29 Mar 2024 11:58:50 +0100 Subject: [PATCH] Transitive dependency projects are not discovered with --also-make Currently it can happen that if one selects a project with -pl / -am this project has initially not any maven dependencies but then later on tycho adds one as a dependency and then the one declared in the pom are not found. This now adds an additional step each time a project is added as a dependency to look if that project also has maven dependencies that map to reactor projects. --- .../tycho/build/TychoGraphBuilder.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tycho-build/src/main/java/org/eclipse/tycho/build/TychoGraphBuilder.java b/tycho-build/src/main/java/org/eclipse/tycho/build/TychoGraphBuilder.java index e654bd9805..1100f3ff40 100644 --- a/tycho-build/src/main/java/org/eclipse/tycho/build/TychoGraphBuilder.java +++ b/tycho-build/src/main/java/org/eclipse/tycho/build/TychoGraphBuilder.java @@ -30,6 +30,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.ForkJoinPool; +import java.util.function.Function; import java.util.stream.Collectors; import org.apache.maven.execution.MavenExecutionRequest; @@ -38,6 +39,7 @@ import org.apache.maven.graph.DefaultGraphBuilder; import org.apache.maven.graph.DefaultProjectDependencyGraph; import org.apache.maven.graph.GraphBuilder; +import org.apache.maven.model.Dependency; import org.apache.maven.model.building.DefaultModelProblem; import org.apache.maven.model.building.ModelProblem; import org.apache.maven.model.building.ModelProblem.Severity; @@ -142,6 +144,8 @@ public Result build(MavenSession session) { } ProjectDependencyGraph graph = graphResult.get(); List projects = graph.getAllProjects(); + Map projectIdMap = projects.stream() + .collect(Collectors.toMap(p -> getProjectKey(p), Function.identity())); int degreeOfConcurrency = request.getDegreeOfConcurrency(); Optional executor; if (degreeOfConcurrency > 1) { @@ -201,6 +205,22 @@ public Result build(MavenSession session) { // we also need to add the dependencies of the dependency project queue.add(new ProjectRequest(project, false, true, projectRequest)); }); + // special case: a (transitive) Tycho project might have declared a dependency + // to another project in the reactor but this can not be discovered by maven + // before we add it here... + List dependencies = projectRequest.mavenProject.getDependencies(); + for (Dependency dependency : dependencies) { + MavenProject reactorMavenProjectDependency = projectIdMap.get(getProjectKey(dependency)); + if (reactorMavenProjectDependency != null) { + if (DEBUG) { + log.info(" + add (maven) dependency project '" + + reactorMavenProjectDependency.getId() + "' of project '" + + projectRequest.mavenProject.getId() + "'"); + } + queue.add( + new ProjectRequest(reactorMavenProjectDependency, false, true, projectRequest)); + } + } } if (projectRequest.addRequires) { dependencyClosure.dependencies(always -> List.of())// @@ -248,6 +268,14 @@ public Result build(MavenSession session) { } } + private String getProjectKey(Dependency project) { + return project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion(); + } + + private String getProjectKey(MavenProject project) { + return project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion(); + } + private List toProblems(IStatus status, List problems) { int severity = status.getSeverity(); if (severity == IStatus.OK || severity == IStatus.INFO) {