How to activate a Maven profile in a dependent module?

前端 未结 2 1910
南旧
南旧 2020-12-18 23:17

Suppose I have a module A:jar, whose runtime and compilation set of dependencies depends on the JDK version. In my example, I have a pre-jdk6-profile

相关标签:
2条回答
  • 2020-12-18 23:58

    a) In a multi-module build, you should always build from the top pom, never from an individual module. If you want to build only one module, use advanced reactor options (see mvn --help) like this:

    mvn -pl mymodule
    

    b) Define and activate the profile in the parent pom, but add the configuration in the child pom.

    parent pom.xml

    <profiles>
        <profile>
             <id>pre-jdk-6</id>
             <activation>
                <jdk>(,1.6.0)</jdk>
             </activation>
        </profile>
    </profiles>
    

    child pom.xml

    <profiles>
        <profile>
            <id>pre-jdk-6</id>
    
            <dependencies>
                <dependency>
                    <groupId>javax.xml.ws</groupId>
                    <artifactId>jaxws-api</artifactId>
                </dependency>
            </dependencies>
        </profile>
    </profiles>
    
    0 讨论(0)
  • 2020-12-18 23:58

    Several notes way after the fact:

    1. When you use -P profName, it activates a profile named 'profName'
    2. After that, it disables all profiles that have an <activation> tag for them. It doesn't matter whether they are activated by the java version, as in the example, or by default or env value or anything.
    3. That means the -P causes any otherwise activated profile to become deactivated.

    Solution: Either use <activation><jdk>...</jdk></activation> or use -P but do not use both.

    0 讨论(0)
提交回复
热议问题