Repository navigation
[MDEP-858] Get rid of maven-artifact-transfer and maven-compat from the get goal - #1677
Conversation
There was a problem hiding this comment.
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-pluginRepositorySessionInjectorthat 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
SnapshotArtifactRepositoryMetadatainto the test tree to keep tests compiling/running withoutmaven-compat, and removes themaven-compatdependency frompom.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.
46046e7 to
192310d
Compare
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)
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)
Copilot review: keeping
|
| 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
dependency:getwas the last goal still resolving throughmaven-artifact-transferand the Maven 3 repository model. It builtorg.apache.maven.artifact.repository.ArtifactRepositoryinstances by hand and then asked the legacyorg.apache.maven.repository.RepositorySystemtoinjectMirror,injectProxyandinjectAuthenticationinto them.It now goes through
ResolverUtil, the waylist-classeshas since MDEP-924.ResolverUtil.remoteRepositories()parses the sameid::layout::urlsyntax into Resolver'sRemoteRepositoryand hands the result toRepositorySystem.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-transferArtifactResolver,DependencyResolver,DependableCoordinate,ArtifactCoordinateArtifactRepository,MavenArtifactRepository,ArtifactRepositoryPolicy,ArtifactRepositoryLayout,ProjectBuildingRequestGetMojonow compiles without a single deprecation warning.maven-artifact-transferstays in the pom —purge-local-repository,copy-dependenciesandArtifactItemstill use it (MDEP-858).Behaviour changes worth a release note
remoteRepositoriesisList<String>instead of a comma-separatedString, same aslist-classessince 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 aString. POM configuration additionally gains the one-per-element form. Both ITs fail withInvalid repository: …if the value is collapsed into a single element, so they are not vacuous.id::url(two tokens) now works, and an unknown layout id is no longer a build failure. Previously onlyid::layout::urland a bare URL were accepted.updatePolicy=always. They follow the session, with-Ustill forcing it — like every other goal that resolves throughResolverUtil.-Dpackaging=test-jarused to download the main jar, because the old code took onlyArtifactHandler.getExtension()and left the classifier empty; the resolverArtifactTypesupplies both, so it now fetches the-testsjar. Same forejb-client. This looks like the intended meaning of the parameter, but it does change what an existing command line downloads.getnow 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'sSimpleArtifactDescriptorPolicy(true, true)still applies.A third,
id::urlno longer being rejected, has an edge: a URL that itself contains::— an IPv6 literal such ashttp://[::1]:8080/repo— is now split into a nonsense id and url instead of failing with "Invalid syntax for repository". That is pre-existingResolverUtilbehaviour shared withlist-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
RepositorySessionInjectorthat reimplementedMavenRepositorySystem's session-basedinjectMirror/injectProxy/injectAuthentication. That was unnecessary —newResolutionRepositoriesdoes 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 emptyAuthentication).Worth recording, since it cost a full IT run to find: maven-core does not export
org.apache.maven.bridgeto 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 exportsorg.apache.maven.artifact.**,org.apache.maven.repository.**,org.apache.maven.settings.**,org.apache.maven.RepositoryUtilsandorg.eclipse.aether.**, and nothing underorg.apache.maven.bridge. Same in 3.9.16 and 4.0.0-rc-5. A plugin referencingMavenRepositorySystemcompiles, passes every unit test, and then fails at runtime withNoClassDefFoundError. The plugin-testing harness uses one flat classpath with no realm isolation, so for changes touching maven-core internalsmvn verifyis not a sufficient bar —-Prun-itsis.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
Settingslist. Same tests, both implementations, same outcomes, so they characterise behaviour rather than agreeing with the new code.testParseRepositoryis dropped along withparseRepository;ResolverUtilTest.prepareRepositoryTestalready covers the same syntax.testMissingArtifactandtestInvalidArtifactreplace the argument validation that stayed in the mojo.The second commit closes two gaps that
parseRepositoryand the mojo's own token check used to cover, and that the migration would otherwise have exposed:parseRepositorytrimmed its regex groups, so-DremoteRepositories="repo1::https://a, repo2::https://b"worked. The converter that turns the property into aList<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>forrepo2then stops matching and credentials are silently not applied. That is the one I would have shipped as a real regression.artifactwith more than five tokens was rejected;ResolverUtilonly checked for fewer than three, so-Dartifact=g:a:v:jar:c:junkwent from a clear failure to silently ignoring the tail.Both are in shared code, so
list-classesgets 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-itssuite is 101 passed / 0 failed (99 baseline + the two new ITs).dependency:analyze-onlyclean.Drafted with Claude — please verify