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
Foo POM Inheritance
This standard parent-child relationship has parent-foo
inherit from the root
, and child-n
inherit from parent-foo
.
root -> parent-foo -> child-n
This is all well & good, and works fine for this trivial case.
(Future) Use Case
Using parent-foo
works for the foo
-based legacy use case, but also test the future use case that we're migrating too: bar
.
Bar
Bar POM Structure
/pom.xml (root POM)
/parent-bar/pom.xml (a parent with 'bar' dependencies & configurations)
/child-1/pom.xml
...
/child-n/pom.xml
Bar POM Inheritance
root -> parent-bar -> child-n
Question
Can I achieve the following reactor build without having to do the workaround each time to modify the child-n
POMs? Or, something like it? Or, is Maven simply 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'd like to just have it all in one reactor build, with each child-n
compiled & used with each parent-*
's inherited dependencies. I know it would leave my Maven repo in an undesired state, but at least I could plug the reactor build into my CI and get assurance that my build ran on both parent-*
dependency platforms.
Current Workaround
The current workaround is to modify all the child-n
POMs' parents, such that:
# 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
Edit 1:
- Noted
root
POM was essentially the "grandparent" POM, per @OhadR's comment. - Noted that both 'foo' and 'bar' are more than just dependency inheritance providers; they also provide build configuration--if they had only provided dependencies, a Maven profile-based solution would have sufficed.
root
is the grandparent. Each parent (foo, bar) has a whole build configuration to inherit (example: JKD6 for one JDK8 for another) in addition to separate dependencies. The goal is to have a common+shared root, common+shared children, and independent/intermediary parents such that they can pass their build/configurations on to the children. A grandparent is a singular static entity, and cannot achieve that solution (by itself, w/o modification).