33

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.

2

2 Answers 2

61

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.

4
  • Really helpful information, thanks! Yes and I reckon may be I should really move the utils modules one level down into the ref-pom modules. Commented May 7, 2016 at 7:10
  • Just to clarify, what does Maven do if it finds the parent POM in a public repository? Or does it still provide a warning even if the parent POM is available in a remote repository such as Maven Central, in which case I must put an empty relative path even for published parent POMs as stackoverflow.com/a/6006098/421049 seems to imply? Commented Mar 20, 2019 at 0:34
  • The warning is issued if the pom pointed at by the relativePath (explicit or implied default) has different coordinates than the on in the parent statement of the current pom. After the warning has been issued, the lookup in local and remote repos is performed. I would not recommend using the empty relativePath, because it would simply hide the warning in that case, without solving the underlying problem.
    – blackbuild
    Commented Mar 27, 2019 at 8:07
  • The 'abuse' of a blank project.parent.relativePath value is only necessary because Maven has no other support for settings import other than extension plugins; ironically a non-parent directory parent is commonly for Maven plugins. It also looks like the Maven developers have realised that installed poms should be flattened by default to remove the, then pointless, parent declaration.
    – Infernoz
    Commented Dec 15, 2020 at 13:58
0

In my case, I was trying to create a simple "Spring Starter Project" but I didn't know why always threw the same error "Non resolvable parent pom...".

So I noticed that in this path: "C:\Users\"youruser"\.m2" I had a file called configuration.xml this file was conflicting with the creations of the project.

Even I noticed that inside .m2 I had a lot of old versioned repositories.

The solution was deleting .m2 folder. And when I create my new "Spring Starter Project" it automatically create a new .m2 in the same path with the repositories with updated versions.

Hope this help anyone :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.