Lyubomir Papazov
Lyubomir Papazov

Reputation: 165

Maven run only the parent pom with a profile

In my project, I have a custom profile custom-profile-name.

A simplified structure of my POM looks like this:

<artifactId>parent</artifactId> <modules> <module>child</module> </modules>

When I run

mvn help:active-profiles -P custom-profile-name

I get:

Active Profiles for Project 'org.sample:parent:pom': The following profiles are active: custom-profile-name

Active Profiles for Project 'org.sample:child': The following profiles are active: custom-profile-name

I've been reading about profile inheritance and If I understand correctly, profiles should not be inherited. Can anyone explain why the custom-profile-name is active in the child module.

My ultimate goal is to execute the parent with one configuration of a custom plugin and all child modules with another configuration of the same plugin.

Upvotes: 1

Views: 1703

Answers (1)

hYk
hYk

Reputation: 789

Not sure why both parent and child modules are getting activated for custom-profile-name. But to get whats needed for you can be done by defining properties inside the profile. Example:

<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>parent-app</name>
<url>http://maven.apache.org</url>

<modules>
    <module>child</module>
</modules>
<profiles>
    <profile>
        <id>default</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <modules>
            <module>child</module>
        </modules>
        <properties>
            <parentProp>foo</parentProp>
            <childProp>foo</childProp>
        </properties>
    </profile>
    <profile>
        <id>custom-profile-name</id>
        <modules>
            <module>child</module>
        </modules>
        <properties>
            <parentProp>xyz</parentProp>
            <childProp>abc</childProp>
        </properties>
    </profile>
</profiles>

The 'parentProp' is a configuration used by the parent pom and 'childProp' is the configuration used by the child pom. From the configuration it can be seen that the default profile and the 'custom-profile-name' profile behaves differently as the values for the properties is different.

Upvotes: 2

Related Questions