Maven - activate profile based on project property

前端 未结 3 967
有刺的猬
有刺的猬 2021-02-14 04:30

Hi I am trying to achieve something like this:

In a parent pom, I have


  
    
      Compil         


        
相关标签:
3条回答
  • 2021-02-14 05:05

    Yes you can activate the profile depending one or variety of parameters like env variables.

    <project>
        ...
        <profiles>
            <profile>
                <id>development</id>
                <activation>
                    <property>
                        <name>!environment.type</name>
                    </property>
                </activation>
            </profile>
        </profiles>
    </project>
    

    If you are trying to have different packaging depending on X than you can use the assembly plugin and do your magic there http://maven.apache.org/plugins/maven-assembly-plugin/

    More on the activation property

    • http://books.sonatype.com/mvnref-book/reference/profiles-sect-activation.html
    • http://earlyandoften.wordpress.com/2011/02/09/disable-maven-profile/
    0 讨论(0)
  • 2021-02-14 05:12

    As of Maven 3.0, profiles in the POM can also be activated based on properties from active profiles from the settings.xml.

    You can check the sample given here :

    http://maven.apache.org/guides/introduction/introduction-to-profiles.html

    0 讨论(0)
  • 2021-02-14 05:20

    It won't work since...

    To begin with:

    • Profile activation works with system properties and not with Maven properties.

    And why it would not work from the parent down to the children:

    • The properties in the parent POM are expanded before your child POM even comes in the picture.

    Many have gone here before you and failed.

    One might wonder what you are really trying to do. Are you building different artifacts from the same source project? Perhaps you need a few more Maven modules to take care of things.

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