In Maven, can a profile override the modules (to not include any)

前端 未结 3 488
孤街浪徒
孤街浪徒 2021-01-11 16:39

In maven, once you define your modules in you pom.xml all profiles aggregate the modules defined in them: (relevant part only)

相关标签:
3条回答
  • 2021-01-11 16:59

    While the question is old, Google still ranks it highly, so it makes sense to add a new answer.

    You can use the activation by absence of a property trick to achieve what you want.

    <profiles>
            <!-- By default, include the modules -->
            <profile>
                <id>full-build</id>
                <activation>
                    <!-- Activation by absence of a property. Run normally, without -Dfull-build -->
                    <property>
                        <name>!skip-modules</name>
                    </property>
                </activation>
                <modules>
                    <module>module1</module>
                    <module>module2</module>
                    <module>module3</module>
                </modules>
            </profile>
    
            <!-- No-modules build -->
            <profile>
                <id>no-modules</id>
                <activation>
                    <!-- Activation by a property. Run with -Dskip-modules to activate -->
                    <property>
                        <name>skip-modules</name>
                    </property>
                </activation>
                <modules>
                </modules>
            </profile>
        </profiles>
    
    0 讨论(0)
  • 2021-01-11 17:06

    It's not possible. Profile configuration is always merged with main configuration, so you only can add modules in your case.

    What you can do instead, however, is to create a some kind of "default" profile (by <activeByDefault>true</activeByDefault> in <activation> section) that is enabled when no other profiles are invoked and put your default modules' list there. Then, when no profile is specified on Maven build call, this "default" profile is used, but when you call explicitly at least one profile, it's not, so you can this way define modules' list from scratch.

    0 讨论(0)
  • 2021-01-11 17:08

    You can do things like this:

      <profiles>
        <profile>
          <id>run-xyz</id>
          <activation>
            <activeByDefault>true</activeByDefault>
          </activation>
          <modules>
            <module>www-ab</module>
            <module>www-cd</module>
          </modules>
        </profile>
    
        <profile>
          <id>run-its</id>
          <activation>
            <activeByDefault>false</activeByDefault>
          </activation>
          <modules>
            <module>www-db</module>
            <module>www-it</module>
          </modules>
        </profile>
      </profiles>
    

    If you are talking about such things. But i would recommend to be very carefull about such things.

    It's only the question how you set activeByDefault. With this it's possible to create more or less any combination.

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