Inheriting Maven profiles
Asked Answered
T

4

37

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

Thibault answered 12/9, 2010 at 15:35 Comment(0)
B
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:

Blond answered 12/9, 2010 at 15:39 Comment(5)
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.Piperpiperaceous
The only probmlem, that in child profiles the help:active-profiles do not show inherited profile, which is misleading I think.Flirtation
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: maven.apache.org/guides/introduction/…Borglum
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.Neely
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 errorsTraumatize
O
12

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

Orlop answered 18/7, 2013 at 17:42 Comment(1)
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.Bovine
W
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.

Wellworn answered 16/3, 2017 at 19:29 Comment(2)
That's a great observation (and explains the behavior I've seen). Do you have a reference to where this is documented?Kyne
@Kyne I don't have a reference handy.Wellworn
S
3

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

Sperry answered 12/9, 2010 at 15:37 Comment(1)
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.Erasmo

© 2022 - 2024 — McMap. All rights reserved.