'parent.relativePath' of imported bill-of materials POM creating warning in Eclipse - eclipse

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 relativePath of 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-bom using <relativePath />?
But if I publish a new a new io.clog:clogr-bom using <relativePath />, does that mean the children of io.clog:clogr-bom need to add an explicit <relativePath>../pom.xml</relativePath> on the aggregated children of io.clog:clogr-bom because they are now inheriting a relative path from io.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) maven needs 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:
maven may locate artifact using GAV coordinates only when that artifact was installed/published in local/remote repository, if that didn't happen maven obviously fails (example: we are bootstrapping new multi-module project)
technically, there is no strict requirement to publish parent pom files (for example, parent/aggregator pom files may contain some information about our build process and we do not want to expose such information), moreover, there is no requirement for parent modules to be a part of reactor, however in that case you must use flatten-maven-plugin when installing/publishing such artifacts
maven resolves parent's pom.xml using following algorithm:
if relativePath is "specified" maven uses it, please note, the absence of relativePath element means that relativePath is ../pom.xml (that is your case) - to nullify the value of relativePath you need to place <relativePath/> element into parent configuration
otherwise maven tries to locate parent pom.xml using GAV coordinates in local repository and in case of failure in remote repositories
so, the general recommendations when dealing with parents are following:
if parent module is a part of multi-module project set the correct value of relativePath (relying on default ../pom.xml is not good idea though)
if parent module is a not part of multi-module project nullify relativePath via specifying <relativePath/>
take advantage of flatten-maven-plugin
In regard to your clogr-bom - that is definitely not a Bill Of Materials, it is just a published aggregator module, in order to be a bom it's content should be following:
<groupId>io.clogr</groupId>
<artifactId>clogr-bom</artifactId>
<version>0.8.3</version>
<packaging>pom</packaging>
<name>Clogr BOM</name>
<description>Parent POM and bill of materials of all Clogr projects.</description>
<url>https://clogr.io/</url>
<inceptionYear>2016</inceptionYear>
<licenses>
<license>
<name>Apache-2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0</url>
<distribution>repo</distribution>
</license>
</licenses>
<organization>
<name>GlobalMentor, Inc.</name>
<url>https://www.globalmentor.com/</url>
</organization>
<developers>
…
</developers>
<scm>
<connection>scm:git:https://bitbucket.org/globalmentor/clogr.git</connection>
<developerConnection>scm:git:https://bitbucket.org/globalmentor/clogr.git</developerConnection>
<url>https://bitbucket.org/globalmentor/clogr</url>
</scm>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.clogr</groupId>
<artifactId>clogr</artifactId>
<version>0.8.3</version>
</dependency>
<dependency>
<groupId>io.clogr</groupId>
<artifactId>clogr-logback</artifactId>
<version>0.8.3</version>
</dependency>
<dependency>
<groupId>io.clogr</groupId>
<artifactId>clogr-logback-provider</artifactId>
<version>0.8.3</version>
</dependency>
<dependency>
<groupId>io.clogr</groupId>
<artifactId>slf4j1-shim</artifactId>
<version>0.8.3</version>
</dependency>
</dependencies>
</dependencyManagement>
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 parent in any project must strip-off information about parent (that is not just about relativePath element, but about the entire parent element), 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 maven to 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":
To me a BOM represents only the set of modules of a multimodule, that contain the versions that work together. This should prevent issues with dependency depth/distance which could pull in an unexpected version.
Ideally all multimodules also provide a BOM.
Other dependencies don't belong here, as they should be upgradable/downgradable independent of the BOM.

Related

How do I update Itext7 to version 7.1.1

This seems like it should be simple but I cannot find anything on how to upgrade to newer versions of itext7. I am using an Eclipse maven project with itext7 version 7.0.4 and would like to update to 7.1.1. However, I can find nothing that tells me how to do that. Neither the Eclipse update menu or the Maven menu has an option to update itext7. Can someone point me to the documentation on how to do an update? TIA.
After answer:
I am not getting the libraries but instead getting conflicts:
I can't seem to post my pom.xml using code tags (I guess the formatter has a problem with XML code because of the <>) but I will include it if someone tells me how. I've uploaded the pom file to DropBox:
pom.xml
(Turning #mkl's and #amedee's comments into an answer)
In your project there is a file pom.xml which contains the Maven project definition. In there is a dependencies section with entries for the iText artifacts (among others). The version is therein. Well, it could also be in a separate dependencies management section or in a parent pom.xml referenced in your file.
As soon as you update the POM file, you can update the Eclipse project configuration in your Eclipse Maven menu. That will, if necessary, automatically download the jar artifacts. If your Eclipse Maven integration is properly configured, that is, and if your computer has proper internet connectivity.
Old versions will remain in your local repository but won't be in the class path anymore.
Also check out our getting started guide. Which contains an example POM snippet.
https://developers.itextpdf.com/itext7/download-and-install-information/Java
If you put your iText version number in POM properties, then you only have to update the value once when you want to upgrade. Like this:
<properties>
<itext.version>7.1.1</itext.version>
</properties>
and then
<dependencies>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>kernel</artifactId>
<version>${itext.version}</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>io</artifactId>
<version>${itext.version}</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>layout</artifactId>
<version>${itext.version}</version>
</dependency>
...
</dependencies>

Parent project to include common maven dependencies

I have reached a point where there are a few projects that include the same dependencies.
I want to create a parent project which only contains a pom file where the common dependencies will reside.
Is there any particular type of project I should choose in jBoss/Eclipse that will help me with this parent project creation.
When making such construction, you usually have 2 choices:
1) Using a common parent that defines these dependencies
2) Adding a Maven module of type "pom", that just lists the common dependencies
Integrating solution 1) is easy, just make a module a child of that project (can be a grandchild of course). Dependencies will be inherited.
<parent>
<groupId>com.mycompany</groupId>
<artifactId>my-company-parent-having-common-deps</artifactId>
<version>1.0.0</version>
</parent>
Integrating solution 2) is easy too. Just add a dependency on the pom module wherever it is needed, for instance:
<dependencies>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>mycompany-module-declaring-bunch-of-deps</artifactId>
<version>1.0.0</version>
<type>pom</type>
</dependency>
</dependencies>
Depending on your project, you'll have to see if solution 1) or 2) suits better.
I recently used a construction like solution 2) when using a JBoss EAP 6 sample: https://github.com/jboss-developer/jboss-eap-quickstarts/tree/6.3.x-develop/helloworld-jms. They created some poms projects to aggregate dependencies that should be used together, such as all dependencies needed for a JMS client.

Maven - how to add a module in parent project's pom as dependency

I have a situation mentioned in this question.
I have a multi-module Maven project with a parent project P and two sub-modules A and B. When I only had A as a sub module it worked fine. I added a new source folder in the main project, created a package and added a class (am i doing something wrong here?), lets call it module B. Now i import the class in package B in a class in package A, but A's pom doesnt get updated to include B as dependency and thus when I try to mvn compile the parent project it gives the error undefined symbol B.
Am I adding project B wrongly? coz it doesnt have any pom in it?
How do I add B as dependency in main project's pom file as mentioned in the referenced question?
Edit: Adding poms and code
here is project A's pom
<dependencies>
<dependency>
<groupId>javax.slee</groupId>
<artifactId>jain-slee</artifactId>
</dependency>
<dependency>
<groupId>org.mobicents.servers.jainslee.core</groupId>
<artifactId>fault-tolerant-ra-api</artifactId>
<version>2.6.0.FINAL</version>
</dependency>
<dependency>
<groupId>org.mobicents</groupId>
<artifactId>hello-slee-world-sbb</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
nowwhere it has B's dependency mentioned. Here is the reference of B in project A.
import BPackage.*;
this is how I have used B in A.
there is only one class in BPackage named BClass. Now I am asking if I am adding the package wrongly i.e. do I need to maven add some thing? so that its pom gets created and its dependency is added in A.
Furthermore I want to build both B and A when I compile the parent so in that case I guess I need to add A in parents pom as well. Here is the parent's pom
<modules>
<module>sbb</module>
<module>customRAType-ratype</module>
<module>customAdaptor-ra</module>
<module>du</module>
</modules>
customAdaptor-ra is project A
Each of your projects needs to have a pom.xml. The top-level project needs to have
<modules>
<module>project1</module>
<module>project2</module>
</modules>
If project2 depends on project1, you need to define a <dependency/> to it inside project2's pom.xml.

Finding missing Maven artifacts

I'm new to Maven, and struggling with adding dependencies. I'm trying to convert an existing project to Maven, and after adding the dependencies for all the jars in my referenced libraries, I'm receiving an error message about missing artifacts:
Missing artifact stax:stax:jar:1.0
Missing artifact clover:clover:jar:1.3-rc4
Missing artifact log4j:log4j:bundle:1.2.16
Missing artifact stax:stax-ri:jar:1.0
From reading this post: How to handle Maven missing artifact errors?, it sounds like I need to manually download these jars and add them to my local maven repository. My question is how do I find these jars? I tried googling them, and I can find jars that have similar names, but not exactly like these, so I'm not sure if they're the right jars.
Any tips for dealing with this problem? The log4j jar is the only one explicitly listed in the referenced libraries of my original project, so I'm guessing the other ones are required by other jars that I have, and I don't know where to find them or what their exact names should be.
Thanks!
Thanks to everyone for responding. The actual cause of the problem is that for each of those 3 missing artifacts, for some reason, when Maven downloaded them into my local repository, .lastUpdated was appended to the end of the jar. For example, stax-1.0.jar.lastUpdated. This is the reason Maven could not find stax-1.0.jar.
So, to fix this problem, I had to manually download stax-1.0.jar, then install it into the local maven repository in the exact same place as the messed up file, so that Maven could find it. (For example, using the command:
mvn install:install-file -Dfile=<path-to-file>/stax-1.0.jar
-DgroupId=stax -DartifactId=stax -Dversion=1.0 -Dpackaging=jar
Using the same exact groupId and artifactId as the existing, incorrect file was crucial in order for maven to find it.
You can find dependency search Sites under maven.apache.org. Go to the left side Navigation Menü entry FAQ (official) and Thun to end of page.
It's more likely that your POM definition is not correct for log4j. Everything relating to log4j should be readily available in maven.
Also, if you know the name of the bundle (such as log4j) you can almost always do a quick google search "[bundle name] maven pom" within the first few hits you should either get the maven repo containing a quick snippet on how to include it, or the actual website for the bundled up jar and the maven instructions.
For example log4j:
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
</dependencies>
Sometimes though you just need to specify the repository to find the item in (if it's not hosted in the greater maven repositories)
You can specify a new repository like so
<repositories>
<repository>
<id>Java.Net</id>
<url>http://download.java.net/maven/2/</url>
</repository>
</repositories>
Finally when you absolutely cannot find the artifact already maven'd up for you (this is usually true for proprietary jars and or drivers that you cannot include with your project) you can have the user manually install the item via command line
mvn install:install-file -DgroupId=[group-id] -DartifactId=[artifact-id] -Dversion=[version] -Dfile=/path/to/the/file -Dpackaging=[type]
You can then reference it in your maven file using the information described above
For example I have a custom reference for a salesforce.com project
mvn install:install-file -DgroupId=com.salesforce -DartifactId=wsc -Dversion=22 -Dfile=\tsclient\H\development\java\wsc-22.jar -Dpackaging=jar
To access it in maven:
<dependency>
<groupId>com.salesforce</groupId>
<artifactId>wsc</artifactId>
<version>22</version>
</dependency>
Finally, you can find the jars (or their maven info) at their respective websites (please note I'm just basing these links off the jar names, these may not be the actual websites, well sans the log4j which I know to be correct)
Stax
Clover
Log4j
Use maven search or mvnrepository.com. If you can not find use google looking for jar in other public repositories, for example for stax:
maven stax-ri pom
My first result is:
http://maven.nuxeo.org/nexus/content/groups/public/stax/stax-ri/1.0/
Other public repositories:
http://download.java.net/maven/2
http://download.java.net/maven/1
http://repository.codehaus.org
http://repository.jboss.org/nexus/content/groups/public-jboss
http://maven.springframework.org/release
you can try to add new repositories to your pom.xml
<repositories>
<repository>
<id>java.net</id>
<url>http://download.java.net/maven/2/</url>
</repository>
<repository>
<id>jboss</id>
<url>http://repository.jboss.com/maven2</url>
</repository>
</repositories>
After several days this stupid error bugged me, I found the following article
The author describes that there is a workspace repository, which may out of date. In my case it helped just to import the correct plugins again. The workspace repository has been updated and everything is fine.
Your problem might be something to do with MNG-4142. This bug means that maven will not download a new snapshot if localCopy is set to true in the artifact maven-metadata-local.xml.
Note that the title of this bug is slightly misleading so it is work reading the comments.
You might think that using the -U flag with maven would fix this problem but apparently this is not the case.
The current workaround seems to be searching for all instances of maven-metadata-local.xml and changing the value of localCopy to false.
I solved this problem by changing the log4j version from 1.2.15 to 1.2.16.
It also could be cause by the dom4j. The same error occurred when I use the following settings.
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>20040902.021138</version>
</dependency>
After changing to the following, the error disappeared.
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>

Missing Maven dependencies in Eclipse multi-module project

I’m using STS 2.9.1 (build on Eclipse 3.7.2) with m2e plugin bundled with STS (v1.0.200.20111228-1245).
I have a problem regarding missing dependencies in Eclipse project that contains several modules, or maybe I don’t fully understand how it should work.
It’s a maven project.
In my Project > Properties > Java Build Path > Libraries I have “Maven Dependencies” library, but it's empty (and that’s the problem).
The main POM doesn’t have any dependencies, but it has several modules declared in it.
Adding a dependency to module’s POM doesn’t add it to the “Maven Dependencies” library (what was my expectation) and leads to Eclipse showing errors in source files.
Adding a dependency to the main POM adds it to the “MD” lib, but of course I don’t want to add all of my modules’ dependencies to the main POM just to have it in “MD” lib and adding every single dependency to the Build Path doesn’t seem right nor practical.
I’ve tried:
Project > Clean,
Maven > Update dependencies,
Maven > Update project configuration,
Unchecking the checkbox: Project > Properties > Maven > Resolve dependencies from Workspace projects.
None of the above seems to do the trick.
Example:
Simplified project structure:
simple.project
...
sample-module
...
pom.xml
pom.xml
simple.project/pom.xml:
<project ...>
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>simple.project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>sample-module</module>
</modules>
<dependencies>
<dependency><!-- This dependency is present in "MD" lib. -->
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
simple.project/sample-module/pom.xml:
<project ...>
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>simple.project</artifactId>
<groupId>test</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>test</groupId>
<artifactId>sample-module</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency><!-- I've expected this dependency also to appear in "MD" lib. -->
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
It is not supposed to work. A project only imports a dependency from another one if it depends on that project (using dependency) or if it inherits from it (using parent). The module element only represents an aggregation.
The question is from time ago, but I solved this creating a Maven Project and adding Maven Modules: right click on project and "New > Project... > Maven > Maven Module".
After that, no more errors were shown in code.
First thing that I see is that you're defining dependencies in a pom parent. There I would expect to see a <dependencyManagement> (see here the doc) structure. In this way the submodules will inherit properly those common dependencies.
Aside from that lets start for the most simple test. Try to compile your project from the maven utility in the command line. If it works then you have a problem in your Eclipse configuration, otherwise the problem is in the way you have defined your project.
If your project compiles properly from the command line, lets see what else can be happening.
The fact that the Maven Dependencies Library is empty means that the Eclipse Maven plugin is not resolving properly your poms. I had quite bad experiences with the embedded STS maven plugin. Try to downgrade it to the m2e 0.10 version. You only need to open the STS DashBoard / Find Updates / Install m2e 0.10
I hope some of these tips can help you.