Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

Where does Maven look for dependencies, in what order, and what goes in settings.xml versus pom.xml? How do you route all downloads through a company Nexus or Artifactory?

Maven looks in the local repository, ~/.m2/repository, first, and only then in remote repositories: Maven Central by default, plus any declared in the POM or in active profiles. settings.xml holds settings for the machine or user, such as credentials, mirrors and proxies, while pom.xml holds the project's build information. To route every download through a company Nexus or Artifactory, we add a mirror with mirrorOf set to * in settings.xml, and the repository manager proxies Central and hosts internal artifacts.

Why this question is asked

Every Maven build starts by finding jars, and when that goes wrong, nothing else works: builds fail on a new laptop, CI downloads the internet every run, or credentials leak into Git. Interviewers ask this to check that we know where Maven looks, which file holds which setting, and how a company typically controls downloads. In this answer, we will follow a dependency lookup step by step, separate what belongs in settings.xml from what belongs in the POM, set up a company mirror, connect credentials to repositories, and look at how to keep passwords safe.

1Where Maven Looks for a Dependency

When the build needs an artifact, such as jackson-databind 2.19.0, Maven first checks the local repository, a folder on our machine, by default ~/.m2/repository. If the jar and its POM are there, it uses them without any network access. This is why the second build on a machine is much faster than the first.

If the artifact is missing, Maven tries the remote repositories in turn. By default there is one, Maven Central, which comes from the super POM, the built-in parent of every POM. A project can add more repositories in its POM, and an active profile in settings.xml can add more too. When Maven finds the artifact, it downloads it into the local repository, so the next build finds it locally.

Step throughResolving jackson-databind 2.19.0
  1. In ~/.m2/repository?
    YesUse it, no networkNoAsk the remote repositories
  2. Is a mirror configured for this repository?
    YesSend the request to the mirror insteadNoSend it to the repository URL
  3. Found remotely?
    YesDownload into ~/.m2/repository and use itNoFail: could not resolve dependency

3 steps in order. Play them, or step through them one at a time.

SNAPSHOT versions are rechecked remotely according to the repository's update policy.

2Settings.xml Versus pom.xml

The two files answer different questions. pom.xml describes the project: its coordinates, dependencies, plugins and how to build it. It is committed to Git and must work on every machine. settings.xml describes the environment the build runs in: which mirror to use, which proxy, the credentials for each server, and profiles that apply to every project on that machine.

There are two settings files. The user settings file is ~/.m2/settings.xml, and the global one is in the Maven installation, at conf/settings.xml. Both are read, and the user file wins when they disagree. A useful rule of thumb: if a value would be different for another developer or on CI, such as a password or a proxy, it goes in settings.xml; if it is part of how the project builds, it goes in the POM.

3Routing All Downloads Through a Company Repository Manager

Most companies run a repository manager, such as Sonatype Nexus or JFrog Artifactory. It proxies Maven Central and other public repositories, caching every artifact it downloads, and it hosts the company's own internal artifacts. It usually exposes a single group URL that combines all of these. To send every request there, we configure a mirror in settings.xml.

XML
<!-- ~/.m2/settings.xml -->
<settings>
<mirrors>
<mirror>
<id>company</id>
<mirrorOf>*</mirrorOf> <!-- every repository -->
<url>https://repo.acme.example/repository/maven-all/</url>
</mirror>
</mirrors>
<servers>
<server>
<id>company</id> <!-- matches the mirror id -->
<username>${env.REPO_USER}</username>
<password>${env.REPO_PASSWORD}</password>
</server>
</servers>
</settings>
$ mvn -B verify
# Downloading from company: https://repo.acme.example/repository/maven-all/com/fasterxml/...

Notice that the log now says 'from company' instead of 'from central'. With mirrorOf set to *, every repository, Central and any declared in a POM, is replaced by the mirror. Builds get faster because artifacts are cached nearby, they keep working if Central is slow or rate limits us, and the company can scan and block artifacts in one place.

4Matching Server Ids to Repositories

Credentials in settings.xml are attached to a server id, not to a URL. Maven applies them to any repository, mirror or distributionManagement entry with the same id. If the ids do not match, Maven sends the request without credentials, and the repository manager answers 401 Unauthorized, which is the most common setup mistake.

XML
<!-- pom.xml: where mvn deploy publishes -->
<distributionManagement>
<repository>
<id>company-releases</id> <!-- must match a <server> id -->
<url>https://repo.acme.example/repository/releases/</url>
</repository>
</distributionManagement>
<!-- settings.xml -->
<server><id>company-releases</id> ... </server> <!-- same id: credentials apply -->

So the POM says where to publish, and settings.xml says how to authenticate. That split keeps passwords out of the project.

5Keeping Passwords Safe

Maven can encrypt passwords in settings.xml. We create a master password with mvn --encrypt-master-password, store it in ~/.m2/settings-security.xml, and then encrypt each server password with mvn --encrypt-password. The encrypted value, wrapped in curly braces, goes into the server entry. This protects against someone reading settings.xml over our shoulder, but anyone with both files can decrypt it, so it is a convenience, not strong security. Maven 4 changes how this works, so check your version.

On CI, the better approach is to keep no passwords in files at all. The pipeline reads credentials from its secret store and passes them as environment variables, which settings.xml references with ${env.REPO_PASSWORD}, as in our mirror example. The settings file itself can then be committed to the CI configuration, because it holds no secrets.

6Follow-up questions

Why is putting <repositories> in every POM discouraged?

Because the repository list then depends on the project, not the environment. Every POM that declares repositories makes Maven query extra URLs for every artifact, which slows builds and can leak internal artifact names to public servers. It also spreads URLs across hundreds of projects, so a change of repository manager means editing all of them. And when the POM is published, its repositories are inherited by consumers. A single mirror in settings.xml, pointing at the company repository manager, solves all of this in one place.

What does mirrorOf with values other than * do?

It narrows which repositories the mirror replaces. central replaces only Central, a list such as central,jboss replaces those ids, and *,!internal replaces everything except the repository with id internal. Most companies use * because the repository manager already proxies everything they need.

How do you check which settings Maven is actually using?

mvn help:effective-settings prints the merged result of the global and user settings files, with passwords masked. Running Maven with -X shows which settings files were loaded. And mvn -s path/to/settings.xml uses a specific file, which is how CI usually supplies its own.

7Conclusion

In this answer, we saw that Maven resolves artifacts from the local repository first and then from remote repositories, Central by default plus any declared in POMs or profiles. settings.xml holds machine and user settings such as mirrors, proxies and credentials, while the POM holds the project's build. A mirror with mirrorOf set to * routes everything through the company repository manager, credentials apply when server ids match repository ids, and passwords are best injected from a secret store on CI.

What to say in the interviewAbout 90 seconds aloud

Open with

Maven always checks the local repository first, which is ~/.m2/repository. If the artifact is not there, it goes to the remote repositories: Maven Central by default, which comes from the super POM, plus any repositories declared in the POM or in an active profile.

Then, if they want more

Whatever it downloads goes into the local repository for next time. The split between the files is environment versus project. pom.xml is the project's build information, committed and the same everywhere. settings.xml, either the user one in ~/.m2 or the global one in the Maven installation, holds machine and user settings: mirrors, proxies, server credentials and profiles.

To route everything through a company Nexus or Artifactory, I add a mirror in settings.xml with mirrorOf set to star, pointing at the repository manager's group URL. That replaces Central and any repository a POM declares, so all downloads go through the manager, which proxies Central and also hosts our internal artifacts.

Credentials go in a server entry whose id must match the mirror, repository or distributionManagement id, otherwise Maven sends no credentials and we get a 401. Passwords can be encrypted with mvn --encrypt-password and settings-security.xml, but on CI I would inject them from the secret store as environment variables.

I also avoid repositories in every POM, because it spreads URLs everywhere and slows resolution.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Apache Maven guides
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Where does Maven look for dependencies, in what order, and what goes in settings.xml...": https://scrivio-interview-library.netlify.app/java/maven/378e456962/