Search code examples
mavennexus

How to force Maven to use a specific repository (and only that)?


I am setting up a local Nexus repository and am trying to convince my local Maven setup to access that repo as the one and only. That Nexus repo has a group maven-central defined that (quoting from the Nexus manual:) "...accesses the Central Repository, formerly known as Maven Central." and is also supposed to cache the downloaded data.

I thus entered my local Nexus repo into my [home]\.m2\settings.xml like this:

    ...
    <profile>
        <id>alwaysActiveProfile</id>
        <repositories>
            <repository>
                <id>RepoSynoProxy</id>
                <name>Nexus Repo on Synology NAS</name>
                <url>http://192.168.1.15:8081/repository/maven-central/</url>
            </repository>
        </repositories>
    </profile>
  </profiles>
  ...
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
  </activeProfiles>
   ...

But for some strange reason, when I run Maven it starts downloading everything from https://repo.maven.apache.org/maven2/ instead of from the local URL, as I would have expected:

...
[INFO] Downloading from : http://192.168.1.15:8081/repository/maven-central/junit/junit/3.8.1/junit-3.8.1.pom
[INFO] Downloading from : https://repo.maven.apache.org/maven2/junit/junit/3.8.1/junit-3.8.1.pom
[INFO] Downloaded from : https://repo.maven.apache.org/maven2/junit/junit/3.8.1/junit-3.8.1.pom (998 B at 7.3 kB/s)
[INFO] Downloading from : http://192.168.1.15:8081/repository/maven-central/junit/junit/3.8.1/junit-3.8.1.jar
[INFO] Downloading from : https://repo.maven.apache.org/maven2/junit/junit/3.8.1/junit-3.8.1.jar
[INFO] Downloaded from : https://repo.maven.apache.org/maven2/junit/junit/3.8.1/junit-3.8.1.jar (121 kB at 1.4 MB/s)
...

My questions thus:

First: any idea anyone, why the requests to http://192.168.1.15:8081/repository/maven-central/... obviously don't work? I am using a freshly downloaded and installed Nexus v3.18.0 here. The Maven-central proxy is already predefined and I have nothing special configured. Apparently that doesn't work "out-of-the-box".

Second: where does Maven have the URL https://repo.maven.apache.org/maven2/... from that it is using as alternative? Is that hardcoded into Maven as fall-back if a repo doesn't work? Can one suppress that so that it ONLY accesses the repo defined in settings.xml?


Solution

  • You need to configure a mirror in the settings.xml that will override the repository definitions in the superpom and in other pom files: https://help.sonatype.com/en/maven-repositories.html