1

SO I have a Parent POM with three modules defined as so:

<modules> <module>m1</module> <module>m2</module> <module>m3</module> </modules> 

The parent also has two dependencies defined on its own modules:

<dependency> <artifiactId>m1</artifactId> </dependency> <dependency> <artifiactId>m2</artifactId> </dependency> 

When I try to build the project the build for the first module fails because it cannot find itself in the repository.

I have already figured out the when building m1 its trying to resolve the parent dependency on m1 in order to build m1. Obviously if you depend on yourself and you don't exist how can you build.

My question is should the Parent POM besides stating the modules have a dependency on them as well? Wondering what the correct practice is here?

NOTE: Parent has no code to itself:

  • parentProj
    • m1
      • java
      • resources
      • m1Pom
    • m2
      • java
      • resources
      • m1Pom
    • m3
      • java
      • resources
      • m1Pom
    • parentPom

1 Answer 1

3

I think you've confused things a bit.

You need three things:

  • An aggregator
  • A parent POM
  • Modules

Your structure should look like this:

your-project/ |- module1/ | |- src/main/java/ | |- src/main/resources/ | |- src/test/java/ | |- src/test/resources/ | |- pom.xml |- module2/ | |- src/main/java/ | |- src/main/resources/ | |- src/test/java/ | |- src/test/resources/ | |- pom.xml |- module3/ | |- src/main/java/ | |- src/main/resources/ | |- src/test/java/ | |- src/test/resources/ | |- pom.xml |- your-parent/ [This is your parent] | |- pom.xml |- pom.xml [This is your aggregator] 

Further clarifications:

  • In your-project/pom.xml you should only define your <modules/> section and not have any other extendable things like <build/>, or <dependencies/>, or <dependencyManagement/> sections.
  • You should have the sections mentioned above in the your-project/your-parent/pom.xml file.
  • Your modules should use your-project/your-parent/pom.xml as their parent.

I'm not sure why you need the parent to depend on modules in the aggregator. I think you most-probably don't want to do this. Define these dependencies explicitly where needed, instead of doing it by default when extending the parent.

Based on my years of experience as a build and release engineer, I would strongly recommend that you not mix the aggregator and the parent. These are logically separate concepts and although they can be the same thing, they actually are not. This way things are much more decoupled and easier to manage. When you change things in the parent, you really only want to be changing the parent, not the whole aggregator. If the two are not separate, this is much more complicated and tends to make things slower for you, if you get what I mean.

Sign up to request clarification or add additional context in comments.

2 Comments

Okay i understand. And what you said makes more sense. So in the end though since the modules inherit the parent's dependencies, the parent should not depend on the the modules themselves.
Yeah, that's right! It's much simpler and cleaner this way.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.