You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by cs...@apache.org on 2026/10/12 17:03:12 UTC
(maven-resolver) branch master updated: GH-1857: Include all repository failures in artifact messages (#2186)
This is an automated email from the ASF dual-hosted git repository.
cstamas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git
The following commit(s) were added to refs/heads/master by this push:
new dbfe933ae GH-1857: Include all repository failures in artifact messages (#2186)
dbfe933ae is described below
commit dbfe933ae47ead5e9e6b5fcd67d80c451c51ff50
Author: Efe <go...@gmail.com>
AuthorDate: Mon Oct 12 20:03:06 2026 +0300
GH-1857: Include all repository failures in artifact messages (#2186)
## What
Include the per-repository failures for unresolved artifacts in `ArtifactResolutionException` messages. The primary cause and existing message format remain unchanged when there is only one failure.
## Why
When artifact resolution fails for different reasons across repositories, the exception message currently reports only one cause. For example, a missing artifact in Central can be hidden by a transfer error from another repository, leaving users without the information needed to distinguish a bad coordinate from an unavailable repository.
## How
Keep the current primary cause selection, then append other recorded failures with the artifact and repository ID. Sort those additional details so the message is stable despite the concurrent map used to store repository failures.
Fixes #1857
## Testing
- Fail-before: the regression test failed on the unmodified implementation because the exception message contained the transfer failure but omitted Central's not-found reason.
- Pass-after: `mvn -pl maven-resolver-api,maven-resolver-impl -am -Dspotless.apply.skip=true -Dspotless.check.skip=true test` — 583 tests passed, 5 skipped.
- `mvn -pl maven-resolver-api spotless:check` — passed.
- `git diff --check` — passed.
The reactor tests ran with Java 25; Spotless was verified separately with Java 17 because the configured formatter is incompatible with Java 25.
## Compatibility
Single-failure messages are unchanged and covered by a regression assertion. Successful resolution behavior is unchanged.
AI assistance was used for analysis and implementation; the patch and tests were reviewed before submission.
---
To make clear that you license this contribution under the [Apache License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0), check one of the following:
- [x] I hereby declare this contribution to be licensed under the [Apache License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0)
- [ ] I hereby declare that I have filed an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
Signed-off-by: Efe Gökdemir <go...@gmail.com>
---
.../resolution/ArtifactResolutionException.java | 28 ++++++++++++++++
.../eclipse/aether/RepositoryExceptionTest.java | 38 ++++++++++++++++++++++
2 files changed, 66 insertions(+)
diff --git a/maven-resolver-api/src/main/java/org/eclipse/aether/resolution/ArtifactResolutionException.java b/maven-resolver-api/src/main/java/org/eclipse/aether/resolution/ArtifactResolutionException.java
index b91a6b7aa..a2477384e 100644
--- a/maven-resolver-api/src/main/java/org/eclipse/aether/resolution/ArtifactResolutionException.java
+++ b/maven-resolver-api/src/main/java/org/eclipse/aether/resolution/ArtifactResolutionException.java
@@ -133,9 +133,37 @@ public class ArtifactResolutionException extends RepositoryException {
buffer.append(": ").append(cause.getMessage());
}
+ String additionalFailures = getAdditionalFailures(results, cause);
+ if (!additionalFailures.isEmpty()) {
+ buffer.append(" (additional failures: ").append(additionalFailures).append(")");
+ }
+
return buffer.toString();
}
+ private static String getAdditionalFailures(List<? extends ArtifactResult> results, Throwable primaryCause) {
+ List<String> failures = new ArrayList<>();
+ for (ArtifactResult result : results) {
+ if (!result.isResolved()) {
+ for (Map.Entry<ArtifactRepository, List<Exception>> entry :
+ result.getMappedExceptions().entrySet()) {
+ for (Exception exception : entry.getValue()) {
+ if (exception != primaryCause) {
+ String message = exception.getMessage();
+ if (message == null) {
+ message = exception.getClass().getSimpleName();
+ }
+ failures.add(result.getRequest().getArtifact() + " from "
+ + entry.getKey().getId() + ": " + message);
+ }
+ }
+ }
+ }
+ }
+ Collections.sort(failures);
+ return String.join("; ", failures);
+ }
+
/**
* This method tries to be smart and figure out "cause", but it results in somewhat incomplete result. Maven Core
* and probably many other code relies on it, so is left in place, but client code should use {@link #getResults()}
diff --git a/maven-resolver-api/src/test/java/org/eclipse/aether/RepositoryExceptionTest.java b/maven-resolver-api/src/test/java/org/eclipse/aether/RepositoryExceptionTest.java
index 8489f7fae..2bcad528d 100644
--- a/maven-resolver-api/src/test/java/org/eclipse/aether/RepositoryExceptionTest.java
+++ b/maven-resolver-api/src/test/java/org/eclipse/aether/RepositoryExceptionTest.java
@@ -64,6 +64,8 @@ import org.eclipse.aether.transfer.NoTransporterException;
import org.eclipse.aether.transfer.RepositoryOfflineException;
import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
public class RepositoryExceptionTest {
private void assertSerializable(RepositoryException e) {
@@ -111,6 +113,42 @@ public class RepositoryExceptionTest {
assertSerializable(new ArtifactResolutionException(Arrays.asList(result)));
}
+ @Test
+ void testArtifactResolutionExceptionMessageIncludesFailuresFromAllRepositories() {
+ RemoteRepository central =
+ new RemoteRepository.Builder("central", "default", "https://repo.maven.apache.org/maven2").build();
+ RemoteRepository corporate = new RemoteRepository.Builder(
+ "corporate", "default", "https://repo.internal.example/repository/maven")
+ .build();
+ Artifact artifact = newArtifact();
+ ArtifactRequest request = new ArtifactRequest()
+ .setArtifact(artifact)
+ .addRepository(central)
+ .addRepository(corporate);
+ ArtifactResult result = new ArtifactResult(request);
+ result.addException(central, new ArtifactNotFoundException(artifact, central, "not found in central"));
+ result.addException(corporate, new ArtifactTransferException(artifact, corporate, "DNS lookup failed"));
+
+ ArtifactResolutionException exception = new ArtifactResolutionException(Collections.singletonList(result));
+ String message = exception.getMessage();
+
+ assertEquals(
+ "The following artifacts could not be resolved: gid:aid:ext:1: DNS lookup failed "
+ + "(additional failures: gid:aid:ext:1 from central: not found in central)",
+ message);
+
+ ArtifactResult reversed = new ArtifactResult(request);
+ reversed.addException(corporate, new ArtifactTransferException(artifact, corporate, "DNS lookup failed"));
+ reversed.addException(central, new ArtifactNotFoundException(artifact, central, "not found in central"));
+ assertEquals(message, new ArtifactResolutionException(Collections.singletonList(reversed)).getMessage());
+
+ ArtifactResult singleFailure = new ArtifactResult(request);
+ singleFailure.addException(corporate, new ArtifactTransferException(artifact, corporate, "DNS lookup failed"));
+ assertEquals(
+ "The following artifacts could not be resolved: gid:aid:ext:1: DNS lookup failed",
+ new ArtifactResolutionException(Collections.singletonList(singleFailure)).getMessage());
+ }
+
@Test
void testArtifactTransferException_Serializable() {
assertSerializable(new ArtifactTransferException(newArtifact(), newRepo(), "error"));