Maven: multiple parent POMs?

I have a multi-module foo project with the following POM structure:

Foo

Foo POM Structure

 /pom.xml (root/'grandparent' POM) /parent-foo/pom.xml (a parent with 'foo' dependencies & configurations) /child-1/pom.xml ... /child-n/pom.xml 

Inheritance Foo POM

This standard parent-child relationship has parent-foo inherits from root and child-n inherits from parent-foo .

 root -> parent-foo -> child-n 

This is good and good, and works great for this trivial case.

(future) Use case

Using parent-foo works for the existing use case of foo , but also checks for a future use case, which we also ported: bar .

Bar

POM panel structure

 /pom.xml (root POM) /parent-bar/pom.xml (a parent with 'bar' dependencies & configurations) /child-1/pom.xml ... /child-n/pom.xml 

Inheritance POM POM

 root -> parent-bar -> child-n 

Question

Can I get the next reactor by building without to use a workaround each time to change the POMs of child-n ? Or something like this? Or, is Maven just the wrong tool for this use case?

 [INFO] ------------------------------------------------------------ [INFO] Reactor Summary: [INFO] [INFO] root ............................................... SUCCESS [INFO] parent-foo ......................................... SUCCESS [INFO] child-1 ............................................ SUCCESS (foo parent) [INFO] ... [INFO] child-n ............................................ SUCCESS (foo parent) [INFO] parent-bar ......................................... SUCCESS [INFO] child-1 ............................................ SUCCESS (bar parent) [INFO] ... [INFO] child-n ............................................ SUCCESS (bar parent) [INFO] ------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------ 

Ideally, I would just like to use all this in one reactor assembly, with each child-n compiled and used with each inherited parent-* dependency. I know that this will leave my Maven repo in an undesirable state, but at least I can connect the reactor to my CI and get the confidence that my build works on both parent-* dependency platforms.

Current workaround

The current workaround is to change all parents of child-n POMs, such as:

 # 1. modify all child-n POMs # Old: root -> parent-foo -> child-n # New: root -> parent-bar -> child-n 2. Run reactor build effective with 'root -> parent-bar -> child-n' dependency tree 

Change 1:

  • The noted root POM is essentially "grandparents", for the comment by @OhadR.
  • It is noted that both "foo" and "bar" are more than just inheritance inheritance providers; they also provide assembly configuration - if they only provided dependencies, it would be possible to use a solution based on the Maven profile.
+5
source share
2 answers

Maven's short answer does not support multiple inheritance; it indirectly supports the concept using the import area in the dependency management section

 <dependencyManagement> <dependencies> <dependency> <groupId>other.pom.group.id</groupId> <artifactId>other-pom-artifact-id</artifactId> <version>SNAPSHOT</version> <scope>import</scope> <type>pom</type> </dependency> </dependencies> </dependencyManagement> 

like its in the management section, the only inconvenience is that you have to explicitly declare the dependencies, but ... what you have achieved:

with different pores - each of which controls a group of related dependencies. Projects need to import these pumps and then use the dependencies without worrying about the dependency version. essentially, this allows the parental pomp to be simple and thin.

+5
source

What are the dependencies between subsidiary projects? only inside each parent * or through parents - *?

If I, where are you, I would create something like this:

 /pom.xml (Parent POM for all projects) /project-foo/pom.xml (BOM for Project Foo. only dependencyManagement for foo-* artefacts) /project-foo/parent/pom.xml (Parent POM for Project Foo. dependencyManagement for external used artifacts. ev.including import of bar BOM) /project-foo/parent/foo-child1/pom.xml (Child Artifact fron Project Foo) /project-foo/parent/foo-child2/pom.xml (Child Artifact fron Project Foo) /project-foo/parent/foo-child3/pom.xml (Child Artifact fron Project Foo) /project-bar/pom.xml (BOM for Project Bar. only dependencyManagement for bar-* artefacts. ev.including import of foo BOM) /project-bar/parent/pom.xml (Parent POM for Project Bar) /project-bar/parent/bar-child1/pom.xml (Child Artifact fron Project Bar) /project-bar/parent/bar-child2/pom.xml (Child Artifact fron Project Bar) /project-bar/parent/bar-child2/pom.xml (Child Artifact fron Project Bar) 

I think that you have an integral integration / assembly for the project (Foo / Bar). then you can specify it in your / project - * / pom.xml

Link from the official maven page: http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Management

I hope I fully understand your problem ...

0
source

Source: https://habr.com/ru/post/1208172/


All Articles