diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/maven/TychoProjectExecutionListener.java b/tycho-core/src/main/java/org/eclipse/tycho/core/maven/TychoProjectExecutionListener.java index 48a3c39aed..f60429ba2e 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/core/maven/TychoProjectExecutionListener.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/core/maven/TychoProjectExecutionListener.java @@ -110,7 +110,7 @@ public void beforeProjectLifecycleExecution(ProjectExecutionEvent event) throws try { resolver.resolveProject(mavenSession, mavenProject); } catch (DependencyResolutionException e) { - ResolverException resolverException = findResolverException(e); + ResolverException resolverException = ResolverException.findResolverException(e); if (resolverException == null) { throw new LifecycleExecutionException( "Cannot resolve dependencies of project " + mavenProject.getId(), null, mavenProject, e); @@ -148,21 +148,6 @@ public void beforeProjectLifecycleExecution(ProjectExecutionEvent event) throws } } - private ResolverException findResolverException(Throwable t) { - if (t != null) { - if (t instanceof ResolverException re) { - return re; - } - for (Throwable sup : t.getSuppressed()) { - if (sup instanceof ResolverException re) { - return re; - } - } - return findResolverException(t.getCause()); - } - return null; - } - private Set checkBuildState(TychoProject tychoProject, MavenProject project) throws CoreException { ReactorProject reactorProject = DefaultReactorProject.adapt(project); DependencyArtifacts artifacts = tychoProject.getDependencyArtifacts(reactorProject); diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2/resolver/ResolverException.java b/tycho-core/src/main/java/org/eclipse/tycho/p2/resolver/ResolverException.java index a15e76f24d..2f0a012ff2 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2/resolver/ResolverException.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2/resolver/ResolverException.java @@ -67,4 +67,19 @@ public Stream explanations() { return explanation.stream(); } + public static ResolverException findResolverException(Throwable t) { + if (t != null) { + if (t instanceof ResolverException re) { + return re; + } + for (Throwable sup : t.getSuppressed()) { + if (sup instanceof ResolverException re) { + return re; + } + } + return findResolverException(t.getCause()); + } + return null; + } + } diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/RepositoryReferenceTool.java b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/RepositoryReferenceTool.java index 6787b5d2b5..ab4e28bc05 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/RepositoryReferenceTool.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/RepositoryReferenceTool.java @@ -17,6 +17,7 @@ import java.io.IOException; import java.util.HashSet; import java.util.Set; +import java.util.stream.Collectors; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.MojoExecutionException; @@ -27,6 +28,7 @@ import org.eclipse.equinox.p2.metadata.IInstallableUnit; import org.eclipse.tycho.ArtifactDescriptor; import org.eclipse.tycho.DependencyArtifacts; +import org.eclipse.tycho.DependencyResolutionException; import org.eclipse.tycho.ReactorProject; import org.eclipse.tycho.TargetPlatform; import org.eclipse.tycho.TychoConstants; @@ -35,6 +37,7 @@ import org.eclipse.tycho.core.TargetPlatformConfiguration; import org.eclipse.tycho.core.TychoProjectManager; import org.eclipse.tycho.p2.repository.RepositoryBlackboardKey; +import org.eclipse.tycho.p2.resolver.ResolverException; import org.eclipse.tycho.p2.tools.RepositoryReferences; /** @@ -144,6 +147,17 @@ private void addTargetPlatformRepository(RepositoryReferences sources, MavenSess sources.addMetadataRepository(repositoryLocation); } catch (IOException e) { throw new MojoExecutionException("I/O exception while writing the build target platform to disk", e); + } catch (DependencyResolutionException e) { + ResolverException resolverException = ResolverException.findResolverException(e); + if (resolverException == null) { + throw new MojoFailureException("Cannot resolve dependencies of project " + project.getId(), e); + } else { + throw new MojoFailureException("Cannot resolve dependencies of project " + + project.getId() + System.lineSeparator() + " with context " + + resolverException.getSelectionContext() + System.lineSeparator() + resolverException + .explanations().map(exp -> " " + exp.toString()).collect(Collectors.joining("\n")), + resolverException); + } } }