Should I have a parent declaration in my POM.xml?

I declared my project as pom.xml to determine the parent, and it starts the assembly of the reactor from all the included modules. Everything builds perfectly and works as expected. It builds in the correct order, all tests work correctly, and I get the expected result.

One of the projects is a shared library. I do not want to add the <parent> declaration here, so I did not. It all works.

My question is: do I need to worry about adding a parent project declaration to any of my subprojects? What are the pros and cons of bilateral relations between projects? If I don’t add the ads, am I going to make it harder later when something stops working?

To rephrase one question: why bother with the <parent> configuration in the pom.xml files of the module?

+4
source share
2 answers

Your question is about the difference between project inheritance and project aggregation. The <parent> link defines the inheritance relationship. The <modules> section in the parent pom.xml defines aggregation. They are different.

If you do not have the <parent> configuration in the pom.xml module, it does not inherit the pom.xml parent configuration. So, let's say you define the dependency version in the parent pom in the <dependencyManagement> section, the pom.xml module without the parent link does not inherit this. Or, if all your child modules should use a shared library, you can define the dependency in the parent pom.xml. However, the pom.xml module without a parent link will not inherit this dependency.

For more information, see Project Inheritance and Project Aggregation

+9
source

It depends on how you customize your build. If you have a properly configured parent pom, basic information like version and groupid can be shared between your projects.

You can define general project configuration information that should be used in all project modules. For instance:

 <modelVersion>4.0.0</modelVersion> <groupId>groupd.id</groupId> <artifactId>artifact.id</artifactId> <packaging>pom</packaging> <version>version</version> 

However, you do not duplicate this information in module projects. The same information can be referenced as follows:

 <parent> <groupId>group.id</groupId> <artifactId>artifact.id</artifactId> <version>version</version> </parent> 

Remember that the parent pom can be used to share additional information than above. You can perform dependency management, manage plugins, and even define reusable profiles.

0
source

All Articles