Fix copy and unpack for artifacts with unavailable parents#1664
Fix copy and unpack for artifacts with unavailable parents#1664brunoborges wants to merge 2 commits into
Conversation
Preserve descriptor-based relocation while falling back to direct artifact resolution when an artifact descriptor cannot be read. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 32540765-8b96-4d21-aafb-e09cc896cd8f
There was a problem hiding this comment.
Pull request overview
This PR restores dependency:copy / dependency:unpack usability for artifacts whose POM descriptor resolution fails due to an unavailable parent POM, by introducing a controlled fallback that resolves the original artifact coordinates directly (while still preferring descriptor-based relocation when available).
Changes:
- Add
ResolverUtil.resolveArtifactWithFallback(...)to fall back to direct resolution whenreadArtifactDescriptorfails, preserving the original descriptor exception as suppressed context if resolution still fails. - Wire the fallback into from-configuration goals via
AbstractFromConfigurationMojo#getArtifact. - Add unit coverage for the fallback path and an integration test project/repository artifact that reproduces the missing-parent scenario.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/org/apache/maven/plugins/dependency/utils/ResolverUtil.java | Introduces fallback artifact resolution and extracts a direct-resolve helper. |
| src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/AbstractFromConfigurationMojo.java | Switches from descriptor-mandatory resolution to fallback-enabled resolution for configured artifact items. |
| src/test/java/org/apache/maven/plugins/dependency/utils/ResolverUtilTest.java | Adds a resolver unit test covering descriptor-failure fallback behavior. |
| src/it/projects/copy-broken-parent/pom.xml | Adds an IT project exercising dependency:copy against an artifact with a missing parent POM. |
| src/it/projects/copy-broken-parent/invoker.properties | Defines invoker goals for the new IT project. |
| src/it/projects/copy-broken-parent/verify.groovy | Verifies the copied artifact is produced in the expected location. |
| src/it/mrm/repository/broken-parent-artifact-1.0.pom | Adds a mock repository artifact whose parent is intentionally unavailable to reproduce the regression. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
elharo
left a comment
There was a problem hiding this comment.
Test failures might be related:
Warning: Could not transfer metadata /.meta/prefixes.txt from/to jvnet-nexus-releases (https://maven.java.net/content/repositories/releases/): (certificate_expired) PKIX path validation failed: java.security.cert.CertPathValidatorException: validity check failed
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.227 s
[INFO] Finished at: 2026-07-19T10:01:50Z
[INFO] ------------------------------------------------------------------------
Error: Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.6.0:check (checkstyle-check) on project maven-dependency-plugin: Failed during checkstyle configuration: Exception was thrown while processing /home/runner/work/maven-dependency-plugin/maven-dependency-plugin/src/test/java/org/apache/maven/plugins/dependency/utils/ResolverUtilTest.java: IllegalStateException occurred while parsing file /home/runner/work/maven-dependency-plugin/maven-dependency-plugin/src/test/java/org/apache/maven/plugins/dependency/utils/ResolverUtilTest.java. 130:93: mismatched input '(' expecting ';': InputMismatchException -> [Help 1]
ascheman
left a comment
There was a problem hiding this comment.
Thanks for the fix — the fallback design is sound: descriptor-based resolution first (so relocation is preserved), with a scoped fallback to the original coordinates only on ArtifactDescriptorException, keeping the descriptor exception as suppressed context. Limiting it to the from-configuration goals is the right call.
The CI failure isn't the expired jvnet-nexus-releases certificate — that's an unrelated infra warning. It's a genuine syntax error in the new test: src/test/java/org/apache/maven/plugins/dependency/utils/ResolverUtilTest.java is missing a closing brace. resolveArtifactWithFallbackWhenDescriptorCannotBeRead() ends with the two verify(...) calls and then a single } at column 0, which closes the method but leaves the class body unclosed (5 { vs 4 }). That's what makes checkstyle fail with mismatched input '(' expecting ';' — and it won't compile either. Adding the method's closing brace fixes it:
verify(repositorySystem).resolveArtifact(eq(repositorySystemSession), any(ArtifactRequest.class));
}
}Two smaller, non-blocking notes:
- The reproducer only exercises
dependency:copy. Since the fix also targetsunpack, anunpackIT against an artifact with an unavailable parent would lock the fallback in end-to-end for both goals. - Copilot's "assert
readArtifactDescriptorwas invoked" is already covered — the test hasverify(repositorySystem).readArtifactDescriptor(...).
Requesting changes for the missing brace; the rest looks good once CI is green.
Maven Dependency Plugin 3.11.0 made artifact descriptor resolution mandatory for
copyandunpack, which prevents otherwise available artifacts from being processed when their POM references an unavailable snapshot parent.This change preserves descriptor-based relocation support, but scopes a fallback to the from-configuration goals: when descriptor reading fails, the original artifact coordinates are resolved directly. Artifact resolution failures still fail the goal and retain the descriptor exception as suppressed context.
A repository-backed integration test reproduces the unavailable snapshot-parent case, and focused resolver coverage verifies the fallback. Existing copy and unpack relocation integration tests continue to pass.
Fixes: #1642