Note that this question is about a parent.relativePath warning in an imported bill-of-materials (BOM), not in the hierarchy of my own POM as with 'parent.relativePath' points at my com.mycompany:MyProject instead of org.apache:apache - Why?.
In Eclipse EE 2022-09 using Java 17 I have a a project with a main POM that extends from our own root POM:
<parent>
<groupId>com.globalmentor</groupId>
<artifactId>globalmentor-root</artifactId>
<version>0.8.13</version>
</parent>
The main POM also brings in dependencies from a bill of materials POM (which we also published):
<dependency>
<groupId>io.clogr</groupId>
<artifactId>clogr-bom</artifactId>
<version>0.8.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
When viewing the POM as source, Eclipse shows this warning:
'parent.relativePath' of POM io.clogr:clogr-bom:0.8.3 points at io.clogr:clogr-bom instead of com.globalmentor:globalmentor-base, please verify your project structure pom.xml /foo-bar
(In case it is relevant, note that I also have the actual source of io.clogr:clogr-bom imported into Eclipse as a separate project.)
I am aware of the purpose of relativePath as used in my own POM and parent POM. But this warning seems to be saying that the it doesn't like the relativePath designation of the imported BOM! Nevertheless the warning references line 5 of my main POM, which is the designation of the parent POM (com.globalmentor:globalmentor-root). Moreover look closely at the error message: it says that the relative path of io.clogr:clogr-bom points to itself! This cannot be the case, as io.clogr:clogr-bom has no relative path designation, and the default I understand is ../pom.xml. There is no way I can think of that io.clogr:clogr-bom could have its relative path pointing at io.clogr:clogr-bom itself.
- Why is there a warning for the
relativePathof an imported BOM, yet the warning references the line for the parent POM coordinates? - How do I fix this: by publishing a new
io.clog:clogr-bomusing<relativePath />? - But if I publish a new a new
io.clog:clogr-bomusing<relativePath />, does that mean the children ofio.clog:clogr-bomneed to add an explicit<relativePath>../pom.xml</relativePath>on the aggregated children ofio.clog:clogr-bombecause they are now inheriting a relative path fromio.clog:clogr-bom, or will they stil get a default of<relativePath>../pom.xml</relativePath>because the relative path does not inherit?
Eclipse is right: your bom is incorrect, let's elaborate that...
in order to build module pom (project object model, do not confuse with pom.xml)
mavenneeds to know where the parent pom.xml is located (if parent is specified), and here we may raise a question: why do we need to specify both parent GAV coordinates (group-artifact-version) and relativePath? And the rationale is following:mavenmay locate artifact using GAV coordinates only when that artifact was installed/published in local/remote repository, if that didn't happenmavenobviously fails (example: we are bootstrapping new multi-module project)flatten-maven-pluginwhen installing/publishing such artifactsmavenresolves parent's pom.xml using following algorithm:relativePathis "specified"mavenuses it, please note, the absence ofrelativePathelement means thatrelativePathis../pom.xml(that is your case) - to nullify the value ofrelativePathyou need to place<relativePath/>element into parent configurationmaventries to locate parent pom.xml using GAV coordinates in local repository and in case of failure in remote repositoriesso, the general recommendations when dealing with parents are following:
relativePath(relying on default../pom.xmlis not good idea though)relativePathvia specifying<relativePath/>flatten-maven-pluginIn regard to your
clogr-bom- that is definitely not aBill Of Materials, it is just a published aggregator module, in order to be a bom it's content should be following:UPD.
Q: Thus any POM that will be published as a parent POM or to be imported needs
<relativePath/>A: My opinion on that is following: any published artifact, which is not intended to be
parentin any project must strip-off information about parent (that is not just aboutrelativePathelement, but about the entireparentelement), the rationale is following:when we consume external dependency, the only information which makes sense for us is it's transitive dependencies, on the other hand specifying parent in external dependency forces
mavento resolve that parent as well, and, unfortunately, that process is error-prone because parent may reside in unreachable repository, may contain mistakes, etc - such glitches are pretty common for projects, which we are considering now as "legacy", however, anything what we are doing now will eventually turn into "legacy" as well.Q: Who says an aggregate POM cannot also serve as a bill of materials by being imported into another project?
A: I do :) Well, actually there is no common opinion about "what is BoM" even across maven team, however I would prefer to share my opinion with Robert Scholte and consider "BoM" as a "Table Of Contents":