Eric B.
Eric B.

Reputation: 24411

Why do I need to specify a repository in my settings.xml file

I've run into a strange Maven configuration issue that I have never encountered before, and am confused as to my solution.

I have a local Nexus server that I use as a mirror for everything. Until now, I've only had the following mirror in my settings.xml file:

    <mirrors>
            <mirror>
                    <id>nexus</id>
                    <mirrorOf>*</mirrorOf>
                    <name>WADA Nexus</name>
                    <url>https://nexus.domain.org/repository/Public/</url>                                                                                               
            </mirror>
    </mirrors>

However, I recently wanted to create my own custom parent pom that I have deployed to my Nexus repo. In my project, I have pointed to my parent pom:

   <parent>
            <groupId>org.domain</groupId>
            <artifactId>root-pom</artifactId>
            <version>1.0.0-SNAPSHOT</version>
    </parent>

However when I now try to run my build, it fails with the following:

ERROR: Failed to parse POMs
org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM: Could not find artifact org.domain:root-pom:pom:1.0.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 9, column 10

For some reason, maven is not trying to look up the parent pom in my Nexus repo.

My only workaround was to define a random repository value in my settings.xml file:

 <repositories>
    <repository>
      <id>nexus</id>
      <releases>
        <enabled>true</enabled>
        <updatePolicy>always</updatePolicy>
        <checksumPolicy>warn</checksumPolicy>
      </releases>
      <snapshots>
        <enabled>true</enabled>
        <updatePolicy>never</updatePolicy>
        <checksumPolicy>fail</checksumPolicy>
      </snapshots>
      <url>https://www.google.com/anythingCanGoHere</url>
      <layout>default</layout>
    </repository>
  </repositories>

Since I've mirrored all Repos/URLs, I can set that url to any value and maven will now pick up my parent pom.

So, why do I even need to specify the repository at all? Shouldn't maven automatically try to resolve the parent pom against maven central or some other default repository?

Upvotes: 4

Views: 1492

Answers (1)

Michael-O
Michael-O

Reputation: 18430

It is not a strange configuration issue, but simply a misunderstanding from your side. What you have done is to populate <distributionManagement/> in your parent POM and added a catch-all mirror in your settings.xml with your local Nexus instance and expect it to work.

Do you actually know what you are mirroring? No! The default, hardcoded repo in Maven is Maven Central. It is a release repo which does not contain any snapshots. Therefore you see the ERROR. The bogus repo is necessary to enable Maven to request snapshots from your Nexus instance otherwise it will only request releases. Nexus in turn has a repo group with Central and your hosted release and snapshots repos.

As long as you don't define any snapshot repos in your POMs (which you shouldn't) Maven will never be able to download any snapshots.

Upvotes: 2

Related Questions