Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell Maven where to search for parent POMs locally?

Tags:

java

maven

I have many Maven projects checked out on my machine in the following format:

my-project/
  pom.xml
my-other-project/
  pom.xml

my-other-project declares that the POM file in my-project is to be used as parent. The issue is that my-project is not in a maven repository yet and these are two separate projects, so maven isn't able to find the parent POM searching locally. Is there a way to tell Maven to look in my-project/ for the parent POM before searching the repository?

Here is the exact error I get when running mvn package:

[INFO] Scanning for projects...
Downloading: https://repo.maven.apache.org/maven2/com/mycom/my-project/1.0.0/pom-base-1.0.0.pom
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for com.mycom:my-other-project:1.0.0: Could not find artifact com.mycom:pom-base:pom:1.0.0 in central (https://repo.maven.apache.org/maven2) and 'parent.relativePath' points at wrong local POM @ line 39, column 11

Edit:

It is possible to set <relativePath>../my-project</relativePath in the parent declaration, but it would be nice if this could happen automatically.

like image 788
Max Avatar asked Jun 07 '15 12:06

Max


People also ask

Where does Maven look for parent POM?

If not specified, it defaults to ../pom. xml . Maven looks for the parent POM first in this location on the filesystem, then the local repository, and lastly in the remote repo. relativePath allows you to select a different location, for example when your structure is flat, or deeper without an intermediate parent POM.

How do I find parent relativePath?

We can find the details in the Maven Model Documentation and sum up the behavior: If there is a pom. xml file in the parent folder, and if this file has the matching GAV coordinate, it is classified as the project's Parent POM. If not, Maven reverts to the repositories.

Where is the POM file located?

The POM file is named pom. xml and should be located in the root directory of your project. A project divided into subprojects will typically have one POM file for the parent project, and one POM file for each subproject.


1 Answers

relativePath is the way to go if you don't want to have the local project in the repo. This is what this element is intended for, as mentioned in the reference documentation:

The relative path of the parent pom.xml file within the check out. If not specified, it defaults to ../pom.xml. Maven looks for the parent POM first in this location on the filesystem, then the local repository, and lastly in the remote repo. relativePath allows you to select a different location, for example when your structure is flat, or deeper without an intermediate parent POM. However, the group ID, artifact ID and version are still required, and must match the file in the location given or it will revert to the repository for the POM. This feature is only for enhancing the development in a local checkout of that project. Set the value to an empty string in case you want to disable the feature and always resolve the parent POM from the repositories.

like image 140
M A Avatar answered Oct 12 '22 13:10

M A