Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven complaining about parent relative path

Consider a maven project with modules consists of some utilities (jar) and some poms for others to reference to if they want to use some of these utilities.

e.g. inside the parent pom.xml

<artifactId>project-parent</artifactId> <modules>   <module>client-ref-pom</module> (a module with just one pom.xml)   <module>server-ref-pom</module> (a module with just one pom.xml)   <module>client-utils</module> (a module with some utility classes, needs to ref. client-ref-pom)   <module>server-utils</module> (a module with some utility classes, needs to ref. server-ref-pom)   <module>utils</module> (a module with some utility classes, needs to ref. project-parent) </modules> 

So if there is another project wishes to use the utils, it will reference to ref-pom as its parent pom, so that the properties can be inherited. This purpose is served.

The current issue is when the module utils also needs to reference to ref-pom as its parent pom (and ref-pom will ref. project-parent as its parent pom), maven is complaining about 'parent.relativePath' pointing to project-parent instead of ref-pom, suggesting to verify again the project structure.

As that is just a warning, I can still compile the project, but I wonder the proper way to setup the project structure so that maven is happy and my purpose is served.

like image 459
user1589188 Avatar asked May 06 '16 00:05

user1589188


People also ask

What is parent relative path in Maven?

The relative path, if not given explicitly, defaults to .. , i.e. the pom in the parent directory of the current project. So Maven checks whether a) there is a pom file in that directory and b) that pom file contains the same coordinates as stated in the parent definition of the current project.

What is relative path in Pom?

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.

How do you create an absolute path in POM xml?

You cannot use an absolute path for your parent pom, the name itself of the configuration entry is quite self explanatory (relative path). From the official Maven model documentation for this element: The relative path of the parent pom.

What is Basedir in Maven?

basedir : The directory that the current project resides in. This means this points to where your Maven projects resides on your system. It corresponds to the location of the pom. xml file.


1 Answers

In order to resolve the parent project, these possible sources are checked:

  • relativePath
  • local repository
  • remote repositories

The relative path, if not given explicitly, defaults to .., i.e. the pom in the parent directory of the current project. So Maven checks whether a) there is a pom file in that directory and b) that pom file contains the same coordinates as stated in the parent definition of the current project.

If a) and b) are true, that pom file is used as the parent for the resolving of the effective pom.

If a) is true, and b) is false, a warning is given, because this usually points to a misconfigured project (as in your case) and the pom is ignored.

If a) is false, the other sources are checked.

So, in your case, I assume you have the following in your utils/pom.xml

<parent>   <groupId>...</groupId>   <artifactId>ref-pom</artifactId>   <version>..</version> </parent> 

which implicitly includes <relativePath>..</relativePath>. So Maven checks the parent directory of utils, finds a POM, but this point is named project-parent instead of the expected ref-pom. Thus the warning.

The following would work:

<parent>   <groupId>...</groupId>   <artifactId>ref-pom</artifactId>   <version>..</version>   <relativePath>../ref-pom</relativePath> </parent> 

(Note that in your text, you write about ref-pom, but in the modules above there is only client-ref-pom and server-ref-pom)

however

You should think about whether this is really what you want, in your case, if the separate *-ref-pom modules are really necessary or if the content of those poms could and should be better placed inside of the respective *-util modules.

like image 124
blackbuild Avatar answered Sep 23 '22 05:09

blackbuild