Safeguard
Security Guides•

Can Maven builds suffer dependency confusion? Repository order explained

How Maven picks a repository when several are configured, why order matters for private artifacts, and how a single mirror and repository manager helps.

Safeguard Security Team
3 min read

It can be a risk if your build mixes repositories carelessly. Maven queries configured repositories in a fixed order and stops at the first valid result, so which repository answers depends on configuration. Route all requests through one repository manager and keep private group IDs served only by your internal source.

How Maven picks a repository

The Apache Maven guide on multiple repositories says remote repository URLs are queried in a set order until one returns a valid result:

  1. Effective settings, global then user.
  2. The local effective build POM: local pom, parents, then the Super POM.
  3. Effective POMs along the dependency path to the artifact.

Profile repositories are checked first within each location, and Central arrives through the Super POM. Mirrors are applied before any download.

So order is deterministic, but it is spread across several files. A repository added deep in a dependency's POM can join the list.

Why order is not the same as safety

A fixed order does not tell Maven which repository is meant to own a coordinate. If a public repository can answer for a name you thought was private, and it answers first or is the only one that has a version you request, you get its artifact. Maven also relies on you to reason about this across your settings and your dependencies' POMs.

One mirror, one repository manager

The Maven mirror guide describes setting mirrorOf to an asterisk to force all repository requests through a single mirror. It adds that the repository must hold all the desired artifacts or proxy the requests to other repositories, and says to use a repository manager if you want a combined view.

<mirrors>
  <mirror>
    <id>internal</id>
    <url>https://repo.internal.example/maven</url>
    <mirrorOf>*</mirrorOf>
  </mirror>
</mirrors>

Now every request goes to one place. In that repository manager, configure rules so your internal group IDs resolve only from the hosted internal repository and never get proxied from outside. The exact setting depends on your manager, so check its documentation.

Inspect what you have

The Maven guide points to two commands for seeing the effective result:

mvn help:effective-settings
mvn help:effective-pom -Dverbose

Read the repository list in the output. Any entry you did not expect is worth investigating.

Also claim your namespace

If you publish public artifacts, verify your groupId on Maven Central so others cannot publish under it. See what is namespace squatting.

Quick check

Does Maven Central stop someone publishing my private groupId?

Only if you have registered and verified that groupId. If you never did, the name may be open to someone else.

Can a dependency add its own repositories to my build?

The multiple repositories guide lists effective POMs along the dependency path as a source of repositories. A mirror with an asterisk redirects those requests to your single mirror.

Safeguard does SBOM and dependency scanning for Java projects, and a free scan will show every coordinate in your build.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.