How to tell Maven where to find parent POMs locally?

I have many Maven projects extracted on my computer in the following format:

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

my-other-project announces that the POM file in my-project should be used as the parent. The problem is that my-project is not in the maven repository yet, and these are two separate projects, so maven cannot find the parent POM search locally. Is there any way to tell Maven to look in my-project/ for the parent POM before looking for 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:

You can set <relativePath>../my-project</relativePath in the parent declaration, but it would be nice if that could happen automatically.

+5
source share
2 answers

You can install my-project in the local maven repository (by default it is in ~/.m2 ).

To do this, go to the my-project directory and use the mvn install command. When this command completes successfully, the mvn package command should complete successfully.

+2
source

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

The relative path of the parent pom.xml file as part of the check. If not specified, the default value is ../pom.xml . Maven looks for the parent POM first in this place on the file system, then in the local repository, and finally in the remote repo. relativePath allows you to choose a different location, for example, when your structure is flat or deeper without an intermediate parent POM. However, the group identifier, artifact identifier, and version are still required and must match the file at the specified location or it will be returned to the repository for POM. This feature is intended only to improve development in local verification of this project. Set the value to an empty string if you want to disable this function and always allow the parent POM from the repositories.

+2
source

All Articles