Skip to content

Commit 37f1f02

Browse files
[MNG-7758] Report dependency problems for all repository
(cherry picked from commit 768ebbc)
1 parent 083716d commit 37f1f02

File tree

5 files changed

+64
-9
lines changed

5 files changed

+64
-9
lines changed

maven-core/src/main/java/org/apache/maven/plugin/PluginResolutionException.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
*/
1919
package org.apache.maven.plugin;
2020

21+
import java.util.List;
22+
import java.util.stream.Collectors;
23+
2124
import org.apache.maven.model.Plugin;
2225

2326
/**
@@ -36,6 +39,18 @@ public PluginResolutionException(Plugin plugin, Throwable cause) {
3639
this.plugin = plugin;
3740
}
3841

42+
public PluginResolutionException(Plugin plugin, List<Exception> exceptions, Throwable cause) {
43+
super(
44+
"Plugin " + plugin.getId() + " or one of its dependencies could not be resolved:"
45+
+ System.lineSeparator() + "\t"
46+
+ exceptions.stream()
47+
.map(Throwable::getMessage)
48+
.collect(Collectors.joining(System.lineSeparator() + "\t"))
49+
+ System.lineSeparator(),
50+
cause);
51+
this.plugin = plugin;
52+
}
53+
3954
public Plugin getPlugin() {
4055
return plugin;
4156
}

maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,17 @@ public Artifact resolve(Plugin plugin, List<RemoteRepository> repositories, Repo
129129
pluginArtifact = pluginArtifact.setProperties(props);
130130
}
131131
} catch (ArtifactDescriptorException e) {
132-
throw new PluginResolutionException(plugin, e);
132+
throw new PluginResolutionException(
133+
plugin, e.getResult().getExceptions(), logger.isDebugEnabled() ? e : null);
133134
}
134135

135136
try {
136137
ArtifactRequest request = new ArtifactRequest(pluginArtifact, repositories, REPOSITORY_CONTEXT);
137138
request.setTrace(trace);
138139
pluginArtifact = repoSystem.resolveArtifact(session, request).getArtifact();
139140
} catch (ArtifactResolutionException e) {
140-
throw new PluginResolutionException(plugin, e);
141+
throw new PluginResolutionException(
142+
plugin, e.getResult().getExceptions(), logger.isDebugEnabled() ? e : null);
141143
}
142144

143145
return pluginArtifact;
@@ -218,9 +220,11 @@ private DependencyNode resolveInternal(
218220
depRequest.setRoot(node);
219221
repoSystem.resolveDependencies(session, depRequest);
220222
} catch (DependencyCollectionException e) {
221-
throw new PluginResolutionException(plugin, e);
223+
throw new PluginResolutionException(
224+
plugin, e.getResult().getExceptions(), logger.isDebugEnabled() ? e : null);
222225
} catch (DependencyResolutionException e) {
223-
throw new PluginResolutionException(plugin, e.getCause());
226+
throw new PluginResolutionException(
227+
plugin, e.getResult().getCollectExceptions(), logger.isDebugEnabled() ? e : null);
224228
}
225229

226230
return node;

maven-core/src/main/java/org/apache/maven/project/DefaultProjectDependenciesResolver.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ public DependencyResolutionResult resolve(DependencyResolutionRequest request)
155155
result.setCollectionErrors(e.getResult().getExceptions());
156156

157157
throw new DependencyResolutionException(
158-
result, "Could not resolve dependencies for project " + project.getId() + ": " + e.getMessage(), e);
158+
result,
159+
"Could not collect dependencies for project " + project.getId(),
160+
logger.isDebugEnabled() ? e : null);
159161
}
160162

161163
depRequest.setRoot(node);
@@ -184,7 +186,9 @@ public DependencyResolutionResult resolve(DependencyResolutionRequest request)
184186
process(result, e.getResult().getArtifactResults());
185187

186188
throw new DependencyResolutionException(
187-
result, "Could not resolve dependencies for project " + project.getId() + ": " + e.getMessage(), e);
189+
result,
190+
"Could not resolve dependencies for project " + project.getId(),
191+
logger.isDebugEnabled() ? e : null);
188192
}
189193

190194
return result;

maven-core/src/main/java/org/apache/maven/project/DependencyResolutionException.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,53 @@
1818
*/
1919
package org.apache.maven.project;
2020

21+
import java.util.List;
22+
23+
import org.eclipse.aether.graph.Dependency;
24+
2125
/**
2226
* @author Benjamin Bentmann
2327
*/
2428
public class DependencyResolutionException extends Exception {
2529

2630
private final transient DependencyResolutionResult result;
31+
private final transient String detailMessage;
2732

2833
public DependencyResolutionException(DependencyResolutionResult result, String message, Throwable cause) {
2934
super(message, cause);
3035
this.result = result;
36+
this.detailMessage = prepareDetailMessage(message, result);
37+
}
38+
39+
private static String prepareDetailMessage(String message, DependencyResolutionResult result) {
40+
StringBuilder msg = new StringBuilder(message);
41+
msg.append(System.lineSeparator());
42+
for (Dependency dependency : result.getUnresolvedDependencies()) {
43+
msg.append("dependency: ").append(dependency).append(System.lineSeparator());
44+
List<Exception> exceptions = result.getResolutionErrors(dependency);
45+
for (Exception e : exceptions) {
46+
msg.append("\t").append(e.getMessage()).append(System.lineSeparator());
47+
}
48+
}
49+
50+
for (Exception exception : result.getCollectionErrors()) {
51+
msg.append(exception.getMessage()).append(System.lineSeparator());
52+
if (exception.getCause() != null) {
53+
msg.append("\tCaused by: ")
54+
.append(exception.getCause().getMessage())
55+
.append(System.lineSeparator());
56+
}
57+
}
58+
59+
return msg.toString();
3160
}
3261

3362
public DependencyResolutionResult getResult() {
3463
return result;
3564
}
65+
66+
@Override
67+
public String getMessage() {
68+
return detailMessage;
69+
}
3670
}

maven-embedder/src/main/java/org/apache/maven/cli/internal/BootstrapCoreExtensionManager.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,7 @@ private List<Artifact> resolveExtension(
178178
List<Artifact> artifacts = nlg.getArtifacts(false);
179179

180180
return artifacts;
181-
} catch (PluginResolutionException e) {
182-
throw new ExtensionResolutionException(extension, e.getCause());
183-
} catch (InterpolationException e) {
181+
} catch (PluginResolutionException | InterpolationException e) {
184182
throw new ExtensionResolutionException(extension, e);
185183
}
186184
}

0 commit comments

Comments
 (0)