Skip to content

Commit 768ebbc

Browse files
[MNG-7758] Report dependency problems for all repository (#1563)
1 parent db33754 commit 768ebbc

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
/**
@@ -35,6 +38,18 @@ public PluginResolutionException(Plugin plugin, Throwable cause) {
3538
this.plugin = plugin;
3639
}
3740

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

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
@@ -132,15 +132,17 @@ public Artifact resolve(Plugin plugin, List<RemoteRepository> repositories, Repo
132132
pluginArtifact = pluginArtifact.setProperties(props);
133133
}
134134
} catch (ArtifactDescriptorException e) {
135-
throw new PluginResolutionException(plugin, e);
135+
throw new PluginResolutionException(
136+
plugin, e.getResult().getExceptions(), logger.isDebugEnabled() ? e : null);
136137
}
137138

138139
try {
139140
ArtifactRequest request = new ArtifactRequest(pluginArtifact, repositories, REPOSITORY_CONTEXT);
140141
request.setTrace(trace);
141142
pluginArtifact = repoSystem.resolveArtifact(session, request).getArtifact();
142143
} catch (ArtifactResolutionException e) {
143-
throw new PluginResolutionException(plugin, e);
144+
throw new PluginResolutionException(
145+
plugin, e.getResult().getExceptions(), logger.isDebugEnabled() ? e : null);
144146
}
145147

146148
return pluginArtifact;
@@ -229,9 +231,11 @@ private DependencyResult resolveInternal(
229231
depRequest.setRoot(node);
230232
return repoSystem.resolveDependencies(session, depRequest);
231233
} catch (DependencyCollectionException e) {
232-
throw new PluginResolutionException(plugin, e);
234+
throw new PluginResolutionException(
235+
plugin, e.getResult().getExceptions(), logger.isDebugEnabled() ? e : null);
233236
} catch (DependencyResolutionException e) {
234-
throw new PluginResolutionException(plugin, e.getCause());
237+
throw new PluginResolutionException(
238+
plugin, e.getResult().getCollectExceptions(), logger.isDebugEnabled() ? e : null);
235239
}
236240
}
237241
}

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
@@ -160,7 +160,9 @@ public DependencyResolutionResult resolve(DependencyResolutionRequest request)
160160
result.setCollectionErrors(e.getResult().getExceptions());
161161

162162
throw new DependencyResolutionException(
163-
result, "Could not resolve dependencies for project " + project.getId() + ": " + e.getMessage(), e);
163+
result,
164+
"Could not collect dependencies for project " + project.getId(),
165+
logger.isDebugEnabled() ? e : null);
164166
}
165167

166168
depRequest.setRoot(node);
@@ -190,7 +192,9 @@ public DependencyResolutionResult resolve(DependencyResolutionRequest request)
190192
process(result, e.getResult().getArtifactResults());
191193

192194
throw new DependencyResolutionException(
193-
result, "Could not resolve dependencies for project " + project.getId() + ": " + e.getMessage(), e);
195+
result,
196+
"Could not resolve dependencies for project " + project.getId(),
197+
logger.isDebugEnabled() ? e : null);
194198
}
195199

196200
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,18 +18,52 @@
1818
*/
1919
package org.apache.maven.project;
2020

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

2529
private final transient DependencyResolutionResult result;
30+
private final transient String detailMessage;
2631

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

3261
public DependencyResolutionResult getResult() {
3362
return result;
3463
}
64+
65+
@Override
66+
public String getMessage() {
67+
return detailMessage;
68+
}
3569
}

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
@@ -226,9 +226,7 @@ private List<Artifact> resolveExtension(
226226
.filter(ArtifactResult::isResolved)
227227
.map(ArtifactResult::getArtifact)
228228
.collect(Collectors.toList());
229-
} catch (PluginResolutionException e) {
230-
throw new ExtensionResolutionException(extension, e.getCause());
231-
} catch (InterpolationException e) {
229+
} catch (PluginResolutionException | InterpolationException e) {
232230
throw new ExtensionResolutionException(extension, e);
233231
}
234232
}

0 commit comments

Comments
 (0)