Skip to content

[MDEP-858] Get rid of maven-artifact-transfer and maven-compat from the get goal - #1677

Merged
slachiewicz merged 3 commits into
apache:masterfrom
slachiewicz:compat-removal-mdep
Aug 9, 2026
Merged

slachiewicz merged 3 commits into
apache:masterfrom
slachiewicz:compat-removal-mdep

Conversation

@slachiewicz

@slachiewicz slachiewicz commented Aug 8, 2026 •

Copy link
Copy Markdown
Member

Stacked on #1678 — base is agent/mdep-get-test-hardening, so the diff here is just this goal's migration. #1678 must merge first; I'll retarget to master then. Followed by #1679 (drop maven-compat).

dependency:get was the last goal still resolving through maven-artifact-transfer and the Maven 3 repository model. It built org.apache.maven.artifact.repository.ArtifactRepository instances by hand and then asked the legacy org.apache.maven.repository.RepositorySystem to injectMirror, injectProxy and injectAuthentication into them.

It now goes through ResolverUtil, the way list-classes has since MDEP-924. ResolverUtil.remoteRepositories() parses the same id::layout::url syntax into Resolver's RemoteRepository and hands the result to RepositorySystem.newResolutionRepositories(), whose documented job is "applying the session's authentication selector and similar network configuration to the given repository prototypes" — the supported replacement for the three legacy inject calls, and the same selectors Resolver consults when it performs the transfer.

What that removes from the goal

maven-artifact-transfer ArtifactResolver, DependencyResolver, DependableCoordinate, ArtifactCoordinate
deprecated Maven 3 repository model ArtifactRepository, MavenArtifactRepository, ArtifactRepositoryPolicy, ArtifactRepositoryLayout, ProjectBuildingRequest

GetMojo now compiles without a single deprecation warning. maven-artifact-transfer stays in the pom — purge-local-repository, copy-dependencies and ArtifactItem still use it (MDEP-858).

Behaviour changes worth a release note

  1. remoteRepositories is List<String> instead of a comma-separated String, same as list-classes since MDEP-924. The comma-separated form is not broken — verified against real Maven on both binding paths, each pinned by an IT: -DremoteRepositories=a,b (get-remote-repositories) and <remoteRepositories>a,b</remoteRepositories> as element text (get-remote-repositories-pom-config), the form used while the parameter was a String. POM configuration additionally gains the one-per-element form. Both ITs fail with Invalid repository: … if the value is collapsed into a single element, so they are not vacuous.
  2. The repository syntax is more permissive. id::url (two tokens) now works, and an unknown layout id is no longer a build failure. Previously only id::layout::url and a bare URL were accepted.
  3. Extra repositories are no longer forced to updatePolicy=always. They follow the session, with -U still forcing it — like every other goal that resolves through ResolverUtil.
  4. A packaging that carries a classifier now implies it. -Dpackaging=test-jar used to download the main jar, because the old code took only ArtifactHandler.getExtension() and left the classifier empty; the resolver ArtifactType supplies both, so it now fetches the -tests jar. Same for ejb-client. This looks like the intended meaning of the parameter, but it does change what an existing command line downloads.
  5. Non-transitive get now reads the artifact descriptor first, so it follows relocation (consistent with 3712611 "Fix artifact relocation support") and downloads the POM alongside the artifact. A missing or invalid POM stays tolerated — the session's SimpleArtifactDescriptorPolicy(true, true) still applies.

A third, id::url no longer being rejected, has an edge: a URL that itself contains :: — an IPv6 literal such as http://[::1]:8080/repo — is now split into a nonsense id and url instead of failing with "Invalid syntax for repository". That is pre-existing ResolverUtil behaviour shared with list-classes; happy to add a guard here if you'd rather it stay loud.

On the earlier approach in this PR

The first version added a RepositorySessionInjector that reimplemented MavenRepositorySystem's session-based injectMirror/injectProxy/injectAuthentication. That was unnecessary — newResolutionRepositories does the same selection through API a plugin is allowed to use — so the class is gone, and with it both review comments (@elharo: it should not be a public standalone class; Copilot: it could return an empty Authentication).

Worth recording, since it cost a full IT run to find: maven-core does not export org.apache.maven.bridge to plugin class realms. In plexus-classworlds a plain package name matches recursively while the .* form matches only classes directly in that package, so maven-core exports org.apache.maven.artifact.**, org.apache.maven.repository.**, org.apache.maven.settings.**, org.apache.maven.RepositoryUtils and org.eclipse.aether.**, and nothing under org.apache.maven.bridge. Same in 3.9.16 and 4.0.0-rc-5. A plugin referencing MavenRepositorySystem compiles, passes every unit test, and then fails at runtime with NoClassDefFoundError. The plugin-testing harness uses one flat classpath with no realm isolation, so for changes touching maven-core internals mvn verify is not a sufficient bar — -Prun-its is.

Tests

The proxy and credential tests come from #1678, where they were shown to fail when the injection is removed from the current implementation. Here they keep passing with the same assertions; they only change where the selection is read from — the repository session's selectors rather than the Settings list. Same tests, both implementations, same outcomes, so they characterise behaviour rather than agreeing with the new code.

testParseRepository is dropped along with parseRepository; ResolverUtilTest.prepareRepositoryTest already covers the same syntax. testMissingArtifact and testInvalidArtifact replace the argument validation that stayed in the mojo.

The second commit closes two gaps that parseRepository and the mojo's own token check used to cover, and that the migration would otherwise have exposed:

  • repository specs were not trimmed. parseRepository trimmed its regex groups, so -DremoteRepositories="repo1::https://a, repo2::https://b" worked. The converter that turns the property into a List<String> splits on , without trimming, so the second element arrives as " repo2::https://b" and the repository is registered under the id " repo2" — a <server> for repo2 then stops matching and credentials are silently not applied. That is the one I would have shipped as a real regression.
  • an artifact with more than five tokens was rejected; ResolverUtil only checked for fewer than three, so -Dartifact=g:a:v:jar:c:junk went from a clear failure to silently ignoring the tail.

Both are in shared code, so list-classes gets the same fix. Each new case fails without it (verified by reverting the fix and re-running).

Numbers

422 unit tests pass; the full -Prun-its suite is 101 passed / 0 failed (99 baseline + the two new ITs). dependency:analyze-only clean.

Drafted with Claude — please verify

@slachiewicz slachiewicz added the dependencies Pull requests that update a dependency file label Aug 8, 2026
@slachiewicz
slachiewicz requested review from elharo and slawekjaranowski and a lite review from Copilot August 8, 2026 17:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Removes the maven-compat test dependency by eliminating GetMojo’s reliance on legacy RepositorySystem injection and instead applying mirrors/proxies/authentication via the active RepositorySystemSession selectors (which are available to plugins at runtime).

Changes:

  • Replaces GetMojo’s legacy mirror/proxy/auth injection with a new in-plugin RepositorySessionInjector that reads from the repository session selectors.
  • Strengthens GetMojo’s unit tests to ensure proxy/auth behavior is actually exercised (including isolating the local repo via @TempDir) and adds focused unit coverage for the new injector.
  • Vendors SnapshotArtifactRepositoryMetadata into the test tree to keep tests compiling/running without maven-compat, and removes the maven-compat dependency from pom.xml.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/main/java/org/apache/maven/plugins/dependency/GetMojo.java Switches repository injection to session-based selectors via RepositorySessionInjector.
src/main/java/org/apache/maven/plugins/dependency/utils/RepositorySessionInjector.java New implementation of mirror/proxy/auth application based on RepositorySystemSession selectors.
src/test/java/org/apache/maven/plugins/dependency/utils/RepositorySessionInjectorTest.java Adds direct unit tests for mirror/proxy/auth behavior of the new injector.
src/test/java/org/apache/maven/plugins/dependency/TestGetMojo.java Updates tests to populate repository session selectors from settings and isolates local repo to ensure transfers occur.
src/test/java/org/apache/maven/artifact/repository/metadata/SnapshotArtifactRepositoryMetadata.java Vendors compat-only metadata class into tests to allow dropping maven-compat.
pom.xml Removes the maven-compat test dependency.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@slachiewicz slachiewicz changed the title Remove maven-compat from GetMojo [MDEP-858] Get rid of maven-artifact-transfer and maven-compat from the get goal Aug 9, 2026
@slachiewicz
slachiewicz changed the base branch from master to agent/mdep-get-test-hardening August 9, 2026 19:37
@slachiewicz
slachiewicz force-pushed the agent/mdep-get-test-hardening branch from 46046e7 to 192310d Compare August 9, 2026 19:56
@slachiewicz
slachiewicz deleted the branch apache:master August 9, 2026 20:21
@slachiewicz slachiewicz closed this Aug 9, 2026
Resolve through ResolverUtil, the way list-classes has since MDEP-924.

ResolverUtil.remoteRepositories() parses the same id::layout::url syntax into
Resolver's RemoteRepository and passes the result to
RepositorySystem.newResolutionRepositories(), which applies the session's
mirror, proxy and authentication selectors. That is the supported replacement
for the legacy injectMirror/injectProxy/injectAuthentication calls on
org.apache.maven.repository.RepositorySystem -- and the same selectors Resolver
consults when it performs the transfer.

Doing so drops the goal's use of maven-artifact-transfer along with the
deprecated Maven 3 repository model: ArtifactRepository,
MavenArtifactRepository, ArtifactRepositoryPolicy, ArtifactRepositoryLayout and
ProjectBuildingRequest. GetMojo now compiles without a deprecation warning.
maven-artifact-transfer stays in the pom; purge-local-repository,
copy-dependencies and ArtifactItem still use it.

Three visible consequences, all shared with list-classes: remoteRepositories
becomes a List<String> rather than a comma-separated String, the repository
syntax accepts id::url and no longer rejects an unknown layout id, and extra
repositories follow the session's update policy rather than being forced to
always.

The proxy and credential tests keep working unchanged in substance -- they now
populate the repository session's selectors rather than only the Settings,
because that is where the selection now reads from. testParseRepository goes
away with parseRepository; ResolverUtilTest covers the same syntax, and two
tests replace the argument validation that stayed in the mojo.

Generated-by: Claude Opus 5 (1M context)
Two gaps in ResolverUtil that the previous commit would otherwise expose to
users of the get goal, because parseRepository and the mojo's own token check
used to cover them:

Repository specs were not trimmed. parseRepository trimmed the id, layout and
url it took from the regex, so

  -DremoteRepositories="repo1::https://a, repo2::https://b"

worked. The converter that turns that property into a List<String> splits on
"," without trimming, so the second element arrives as " repo2::https://b" and
the repository is registered under the id " repo2" -- a <server> entry for
repo2 then no longer matches it and the credentials are silently not applied.

An artifact string with more than five tokens was rejected; ResolverUtil only
checked for fewer than three. -Dartifact=g:a:v:jar:c:junk went from a failure
naming the expected format to silently ignoring the tail.

Both live in shared code, so list-classes gets the same fix.

Generated-by: Claude Opus 5 (1M context)
@slachiewicz slachiewicz reopened this Aug 9, 2026
@slachiewicz
slachiewicz changed the base branch from agent/mdep-get-test-hardening to master August 9, 2026 20:26
@slachiewicz
slachiewicz requested a lite review from Copilot August 9, 2026 20:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

Review raised that turning remoteRepositories from a comma-separated String
into a List<String> could leave "-DremoteRepositories=a,b" arriving as a single
element that still contains the comma. The existing unit test only ruled that
out implicitly -- such an element would split on "::" into five tokens and
throw -- so make it explicit and cover the paths a user actually goes through.

testRemoteRepositories now asserts the injected field holds one element per
repository rather than only executing the mojo.

Two integration tests cover real Maven, one per binding path: a user property
(get-remote-repositories) and the text of a single <remoteRepositories> element
in a POM (get-remote-repositories-pom-config), which is how the parameter was
written while it was a String. Both name two repositories in one comma
separated value and use both accepted forms, id::layout::url and id::url. The
mrm mirror matches "*", so the .invalid hosts are never contacted; collapsing
the value into one element instead fails the goal with "Invalid repository",
which is what makes these tests worth having.

Also document the per-element POM form on the parameter itself.

Generated-by: Claude Opus 5 (1M context)
@slachiewicz

Copy link
Copy Markdown
Member Author

Copilot review: keeping List<String>

All four comments were about the same change — remoteRepositories going from a comma-separated String to List<String> — so answering once here as well as in the threads.

Decision: the parameter stays List<String>. It matches list-classes, which has had this exact type since MDEP-924 in 3.7.0, and reverting would leave the two sibling goals inconsistent for no gain.

The concern was worth checking rather than dismissing, so I tested it against real Maven instead of reasoning about it. Both binding paths keep working, and each is now pinned by an integration test:

path IT
-DremoteRepositories=a,b src/it/projects/get-remote-repositories
<remoteRepositories>a,b</remoteRepositories> as element text src/it/projects/get-remote-repositories-pom-config

The second is the real compatibility risk — it is how the parameter was written while it was a String. Both ITs name two repositories in one comma-separated value and exercise both accepted forms, id::layout::url and id::url.

They are not vacuous. Collapsing the value into a single element, Collections.singletonList(String.join(",", remoteRepositories)), fails the goal with exactly the mode Copilot predicted:

Failed to execute goal ...:get (default-cli) on project get-remote-repositories:
  Invalid repository: repo1::default::https://repo1.invalid/maven2,repo2::https://repo2.invalid/maven2

The mechanism: sisu-plexus' AbstractCollectionConverter.csvToXml turns a plain string value into synthetic list children by splitting on ,, and that is the same code path for a user property and for POM element text.

Two of the comments were right about the test rather than the code: testRemoteRepositories only ruled the failure out implicitly, since a comma-bearing single element would split on :: into five tokens and throw. It now asserts the injected field directly. The documentation point was fair too — the javadoc shows the one-per-element POM form alongside the comma form.

I did not add the suggested defensive comma-splitting inside the list: the converter demonstrably splits already, so it would be unreachable for every input a user can actually produce.

422 unit tests, 101 ITs, all green.

Drafted with Claude — please verify

@slachiewicz
slachiewicz merged commit b70b5d1 into apache:master Aug 9, 2026
17 checks passed
@github-actions github-actions Bot added this to the 3.11.1 milestone Aug 9, 2026
@slachiewicz slachiewicz removed the dependencies Pull requests that update a dependency file label Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants