Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
918 views
in Technique[技术] by (71.8m points)

maven - Activating a Child Profile from a Parent Profile

I have the following parent pom.xml file:

<profile>
    <id>build_full</id>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
    <modules>
        <module>mymodule_interface</module>
        <module>mymodule_switch</module>
        <module>mymodule_switch_simulator</module>
        <module>mymodule_switch_controller</module>
        <module>mymodule_server</module>
    </modules>
</profile>

and in my child pom for mymodule_server, I have the following:

<profile>
    <id>subprofile</id>
    <modules>
        <module>...various modules...</module>
    </modules>
</profile>  
<profile>
    <id>default</id>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
    <modules>
        <module>...various modules...</module>
    </modules>
</profile>  

How, when I invoke maven: mvn -P build_full, can I force the child module (mymodule_server) to use profile subprofile rather than default?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

No, you can't activate a child profile from a parent profile. More generally, you can't activate or deactivate any profile from any other profile (there is a JIRA feature-request MNG-3309). What you can do is activate two profiles based on the same property.

First of all, using a profile that is activated by default is generally not a good idea. What you want is to activate a profile based on some condition (OS version, system property...). To solve your problem, you can activate build_full profile when a certain system property is present, and make sure that subprofile is also activated when that same property is present.

A sample configuration would be the following, where both profiles are activated when the fullBuild system property is set to true. Invoking Maven with mvn -DfullBuild=true ... will thus activate both profiles.

<profile>
    <id>build_full</id>
    <activation>
        <property>
            <name>fullBuild</name>
            <value>true</value>
        </property>
    </activation>
    <modules>
        <module>mymodule_interface</module>
        <module>mymodule_switch</module>
        <module>mymodule_switch_simulator</module>
        <module>mymodule_switch_controller</module>
        <module>mymodule_server</module>
    </modules>
</profile>
<profile>
    <id>subprofile</id>
    <activation>
        <property>
            <name>fullBuild</name>
            <value>true</value>
        </property>
    </activation>
    <modules>
        <module>...various modules...</module>
    </modules>
</profile>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...