Skip to content

Remove maven-compat from GetMojo - #1677

Open
slachiewicz wants to merge 1 commit into
apache:masterfrom
slachiewicz:compat-removal-mdep
Open

Remove maven-compat from GetMojo#1677
slachiewicz wants to merge 1 commit into
apache:masterfrom
slachiewicz:compat-removal-mdep

Conversation

@slachiewicz

Copy link
Copy Markdown
Member

Removes maven-compat. No baseline change — the pom is already maven 3.9.16 / resolver 1.9.25, so <prerequisites> is untouched.

GetMojo's constructor loses a parameter: the legacy org.apache.maven.repository.RepositorySystem was only ever used for injectMirror, injectProxy and injectAuthentication.

Not via MavenRepositorySystem — it is not visible to plugins

That swap was made first and it does not work. 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.

It compiled and 412 unit tests passed. It failed only under -Prun-its:

Failed to execute goal ...:get (default-cli) on project get-gav:
  A required class was missing while executing ...:get: org/apache/maven/bridge/MavenRepositorySystem

So for changes touching maven-core internals, mvn verify is not a sufficient bar — the plugin-testing harness uses one flat classpath and has no realm isolation.

Selection now lives in the plugin, in a new RepositorySessionInjector. That is viable because the session-based inject methods need no privileged API: they only read session.getMirrorSelector() / getProxySelector() / getAuthenticationSelector() and write onto the ArtifactRepository.

Two details replicated from maven-core rather than assumed: createArtifactRepository substitutes new ArtifactRepositoryPolicy() for null policies — a naive new MavenArtifactRepository(...) would reintroduce the null-policy trap — and it honours ArtifactRepositoryLayout2.newMavenArtifactRepository.

Proxy and authentication: preserved, with three narrow deltas

Mirrors are unchanged. maven-core's getMirror(ArtifactRepository, List<Mirror>) and resolver's DefaultMirrorSelector were compared directly: same two-pass lookup, same matchPattern handling of *, external:*, external:http:*, !id and comma lists, same layout matching.

Proxies — three differences, all moving toward what the rest of Maven already does:

  1. An http proxy now also applies to https repositories when no https proxy is defined. The legacy equalsIgnoreCase did not fall back, so a repository that previously bypassed the proxy will now be proxied. This is the release-note item.
  2. dav: / davs: are normalised to http/https before matching; the legacy code matched the literal string and never matched.
  3. nonProxyHosts matching is now case-insensitive. Same | splitting and ./* escaping.

Authentication — two differences, both inert: a <server> with no credentials yields null rather than Authentication(null, null), which RepositoryUtils.toAuthentication collapses to null anyway; and duplicate <server> ids go first-wins to last-wins.

Suggested release note: "dependency:get now selects proxies through the repository session, so an http proxy also applies to https repositories when no https proxy is configured, matching how Maven proxies every other download."

The existing auth test was not testing anything

test:test:1.0 persists in the checked-in target/test-classes/unit/get-test/target/local-repo, so without clean the test passed with authentication injection deleted outright. Fixed with a @TempDir local repository. After that, deleting the inject call fails all three of testRemoteRepositoriesAuthentication, testRemoteRepositoriesProxy and testRemoteRepositoriesNonProxyHosts — and the proxy test asserts the failure names the proxy host, so it cannot pass for the wrong reason.

The new tests were also run against unmodified master's settings-list implementation: 6/6 pass. Same tests, both implementations, same outcomes — so they characterise behaviour rather than merely agreeing with the new code.

Numbers

unit ITs
baseline origin/master 410 / 0 / 0 / 1 skip 99 passed, 0 failed
after 420 / 0 / 0 / 1 skip 99 passed, 0 failed

Full 94-project IT suite both sides, per-IT diff empty across all 86 reported projects, dependency:analyze-only clean.

One judgement call

SnapshotArtifactRepositoryMetadata is vendored into the test tree rather than deleting its two usages. TestCopyDependenciesMojo2.assertArtifactExists iterates artifact.getMetadataList() and asserts a file exists — dropping the attachment makes that loop empty and silently removes the check. Vendoring is safe here: the whole hierarchy above it is in maven-core and only the leaf is compat-only. Same approach as MPLUGIN-384.

GetMojo used the legacy org.apache.maven.repository.RepositorySystem, whose
only implementation, LegacyRepositorySystem, lives in maven-compat. It used it
for nothing but injectMirror/injectProxy/injectAuthentication on the
repositories named by the remoteRepositories parameter.

org.apache.maven.bridge.MavenRepositorySystem is the usual replacement but a
plugin cannot use it: maven-core does not export org.apache.maven.bridge to
plugin class realms, so referencing it compiles, passes every unit test, and
then fails at runtime with NoClassDefFoundError. Do the same selection in the
plugin instead, in RepositorySessionInjector, against the repository session's
mirror, proxy and authentication selectors -- Maven builds those from the same
settings, already decrypted, and Resolver consults them itself when it
transfers. Everything it touches is in a package maven-core does export.

Also copy SnapshotArtifactRepositoryMetadata from maven-compat into the test
tree, the only other thing the plugin needed from it, and cover the proxy and
credential paths, which had no test that failed when the injection was
removed.
@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

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.

Comment on lines +186 to +190
Authentication result = new Authentication(
authCtx.get(AuthenticationContext.USERNAME), authCtx.get(AuthenticationContext.PASSWORD));
result.setPrivateKey(authCtx.get(AuthenticationContext.PRIVATE_KEY_PATH));
result.setPassphrase(authCtx.get(AuthenticationContext.PRIVATE_KEY_PASSPHRASE));
return result;
* <code>settings.xml</code>, with the servers and proxies already decrypted, and they are the same selectors
* Resolver consults when it performs the transfer.
*/
public class RepositorySessionInjector {

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.

There seems to be only one use of this class. Unless you intend this to be a general utility for external use, consider moving it into the package where it's used and making it non-public

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants