Maven complains about parent relative path

Consider a maven project with modules, consisting of some utilities (jar) and some poms, so that others refer to whether they want to use some of these utilities.

eg. inside 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 that wants to use utils, it refers to ref-pom as the parent pom, so the properties can be inherited. This goal is being served.

The current problem is that the utils module should also refer to ref-pom as the parent pom (and ref-pom will refer to project-parent as the parent pom), maven complains about specifying parent.relativePath for project-parent instead of ref -pom, offering to check the project structure again.

Since this is just a warning, I can still compile the project, but I am wondering how to properly set up the project structure so that maven is satisfied and my goal is served.

+6
source share
1 answer

To solve the parent project, these possible sources are checked:

  • relativePath
  • local repository
  • remote repositories

The relative path, if not specified explicitly, defaults to .. , that is, pom in the parent directory of the current project. Therefore, Maven checks to see if there is a pom file in this directory and b) this pom file contains the same coordinates as those specified in the parent definition of the current project.

If a) and b) are true, then the pom file is used as the parent to resolve the effective pom.

If a) is true and b) is false, a warning is issued because this usually indicates a misconfigured project (as in your case), and pom is ignored.

If a) false, other sources are checked.

So, in your case, I suppose 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 utils parent directory, finds the POM, but this point is called project-parent instead of the expected ref-pom . So a warning.

The following steps will work:

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

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

but

You should consider whether this is really what you want, in your case, if you really need separate *-ref-pom modules or if the contents of these priests can and should be better placed inside the corresponding *-util modules,

+11
source

All Articles