34

Is it possible for a child POM to inherit profiles defined in the parent POM? If so, how?

Noremac
  • 3,445
  • 5
  • 34
  • 62
Gili
  • 86,244
  • 97
  • 390
  • 689

4 Answers4

42

Profiles defined in a parent POM are inherited in a child POM extending the parent, there is nothing to do. And just in case, the Maven Help Plugin has very useful goals allowing to deal with profiles:

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • It was sort of an add-on to your answer (an example), not really an answer in its own right. Then I realized I had misread the OP question. – Justin Sep 13 '10 at 15:49
  • 4
    The only probmlem, that in child profiles the help:active-profiles do not show inherited profile, which is misleading I think. – Gábor Lipták Sep 30 '10 at 15:55
  • 4
    This "problem" you refer is because Maven DOES NOT SUPPORT PROFILE INHERITANCE. The profiles get executed in the parent POM, not the child pom, so depending on what the profile does it *may* feel like it was inherited. See what Maven supports for inheritance here: http://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Project_Inheritance – Dave May 03 '16 at 21:13
  • FWIW, I have found using Maven 3.2 and Maven 3.5 (latest) that `help:all-profiles` does not report activation correctly for child projects. It will report all inherited profiles from the parent as inactive, whether they are actually active or not. – user1071914 May 11 '17 at 17:35
  • Downvoted, as gigi2's answer states, profiles are just "kind of" inherited, and gigi2's links provide a more complete answer that will help other users understand some nasty errors – efaj Aug 13 '18 at 15:55
10

I don't think it is inherited. http://www.dashbay.com/2011/03/maven-profile-inheritance/ http://looking4q.blogspot.com/2011/01/maven-profiles-inheritance.html You may find the profiles available is very likely because they are activated by default

gigi2
  • 1,996
  • 1
  • 17
  • 22
  • 2
    The first link seems very good; you might consider summarizing its content in your answer. So the result is that they're *kind of* inherited, but not fully: only some of the functionality will be inherited and inherited profiles might have impact only to the parent pom where they are defined, not child poms. – eis Jan 23 '15 at 12:21
6

I tested profile inheritanced with maven 3.3.9. If the parent pom declares the child module (aggregation), the profile is visible in the child module. If the parent pom does not declare de child module (inheritance), the profile is not visible.

Paulo Merson
  • 13,270
  • 8
  • 79
  • 72
4

It's not just possible, it's mandatory. If you declare a parent POM, you get all its profiles.

bmargulies
  • 97,814
  • 39
  • 186
  • 310
  • Can you provide a source to that? This is leading to my extreme frustration where I want to _run a goal only by activation and only in the parent_. My thinking was that I could do it via a profile, but no I'm not sure sure. – mkobit Feb 23 '16 at 21:43