I have a maven project
- Parent Project (with the following modules) (package type pom)
- API Project (package type jar)
- Packaging Project (has a dependency on API Project) (package type custom)
I want to be able to deploy the API project to Nexus repositories so others can leverage that code. The Packaging Project is more of a supporting utility project for a smaller set of deployment use-cases. The Parent Project wraps it all together for me.
When I deploy the API project to the nexus repo, it deploys fine. If i try to make a brand new project that has a depdency on API, it finds the API dependency in nexus but then also wants the Parent project as well. Is there any way to get around publishing the parent project as its really isnt necessary for use of the API lib when used via the nexus repo?
Any tips on how to organize my maven proj to support this?
When you add a
<parent>reference to a Maven project what you are doing is saying: “Take all the configuration from that parent and inject it into my model, then override with the following”Therefore, in order for Maven to build the model of your project, it is necessary for Maven to retrieve the parent itself. In other words, adding a
<parent>tag creates an explicit hard dependency between the parent and the child.The good news is that Inheritance does not have to follow Aggregation. What does that exactly mean?
Aggregation is when you list
<modules>in your pom. It tells Maven that the reactor (i.e. the set of projects that Maven builds) should also include the following (sub)projects.Inheritance is when you set a project’s
<parent>.Nowhere does Maven enforce that a project’s
<parent>has to list its children as<modules>and nowhere does Maven enforce that a projects<modules>must list the project as a<parent>.Some people will set up their project like so
where the parent of
ROOT,apiandpackagingis actually a child ofROOT. Or sometimesROOTwill be a standalone project with no parent [In fact this is a pattern I use a lot myself. When I am working on several related project I will throw together an aggregatingpom.xmlon my local disk and open that with my IDE and that way all the related code is available as one single “project”, even though the actual modules may come from different sources]So in your case the solution would be to remove the
<parent>tag from your “API” module.Now! There is a downside. When you remove the
<parent>tag from your “API” module you have removed all the defaults that your parent project is providing, so you will need to copy those defaults that are relevant to the “API” project or else you may find subtle changes in behaviour. For example, you should definately copy over the pinning of plugin versions, and any<dependencyManagement>that is relevant to the “API” dependencies. There are other bits you may have to copy, but you should use the Maven commandmvn help:effective-pombefore and after removing the<parent>tag as an aid to seeing the effective differences