Search code examples
mavendependenciesrepository

Maven dependency mapping to repositories


I'm new to Maven, although I'm experienced with Ant. I'm trying to understand the process of downloading dependencies. Let's say I've defined two repositories:

And one dependency:

  • dependency
    • groupId:org.mystuff
    • artifactId:mystuff-core

My questions:

  1. I assume that the groupId of a dependency must be found as a subpath of one of the repo URLs, for example, http://repo-one.com/repos/org/mystuff. Is that right?

  2. If so, then the artifactId is sought as an additional subpath, for example, http://repo-one.com/repos/org/mystuff/mystuff-core. Is that right?

  3. If yes to both of the above, what if there is both an http://repo-one.com/repos/org/mystuff/mystuff-core, and an http://repo-two.com/repos/org/mystuff/mystuff-core? Does the first repository listed win?

  4. If I'm completely off the track, what is the process for finding the dependencies on the respositories?

As you can probably tell, I'm looking at an existing POM and trying to understand just how it works. I've reviewed the documentation on the Maven site, but so far I don't see anything that explicitly states how dependencies are mapped to repositories.


Solution

  • Q1. and Q2. You are right.

    More precisely, by default (i.e. if the repository layout wasn't redefined to a non standard layout) : the artifact will found at <REPO_URL>/${groupId_with_dot_replaced_by_subdir}/${artifactId}/${version}/${artifactId}-${version}.${extension}

    Q3. Yes, the first repository containing the artifact wins. Note that

    • if the artifact is not a SNAPSHOT and is already in your local repository it won't be downloaded again.
    • if the artifact is a SNAPSHOT and is in your local repository for a longer time than specified by the refresh policy: it will be downloaded again.

    Q4. Here is a link to blog post explaining the maven repository layout