theINtoy
theINtoy

Reputation: 3708

Maven2: Multiple inheritence or profile selection

I have a Master/Child pom project with many child modules. For some of the child modules I have a series of tasks that only they need to undertake, basically read a properties file to configure a jboss deploy location.

At present I have copied the build section into a few POMs and this is now starting to ring alarm bells. I really should write this once and use it many.

This has set me on a philosphical path.

a) I believe I could create a profile in the master POM and when running the child POMs enable this profile thus using the defined functionality from the Parent POM. This keeps the current structure in place of 1 parent : many children. It also raises the question, could I actually activate that profile in the child POM so that the person doing the build on the child did not have to use a -P command line option?

b) I could change the exisiting parent/master POM in to a grandparent and inherit the master POM into a new parent pom, adding the property reading/jboss deploying facilities to this new parent. The child POMs requiring this functionality would then inherit from the new Parent, giving me a grandfather-father-son inheritence. This would mean that the person doing the build would not need to rememeber the commandline at the cost of another level of inheiritence.

Question is, which method is the "maven way"?

Upvotes: 0

Views: 132

Answers (1)

user944849
user944849

Reputation: 14971

Unfortunately option a) is not supported by Maven. I had a similar situation to solve and tried the child-enables-profile-defined-in-parent bit, only to find it doesn't work; details elsewhere in StackOverflow.

I don't know if there is an official best practice, as I didn't find one when I did my hunt before. I used a combination of grandparent/parent/child POMs and the <pluginManagement> configuration.

I would try <pluginManagement> in your parent POM first. If that doesn't quite meet the need the extra POM level might work. Good luck!

Upvotes: 1

Related Questions