Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to activate profile by means of maven property?

I'm trying to activate a maven profile using a property defined inside pom.xml:

<project>
  [...]
  <properties>
    <run.it>true</run.it>
  </properties>
  [...]
  <profiles>
    <profile>
      <activation>
        <property><name>run.it</name></property>
      </activation>
      [...]
    </profile>
  </profiles>
  [...]
</project>

Apparently it doesn't work. However, activation works from the command line:

mvn -Drun.it

Is it "by design"? If it is, what is a possible workaround?

like image 807
yegor256 Avatar asked Apr 15 '11 11:04

yegor256


People also ask

Can Maven profile be defined in POM xml?

A profile in Maven is an alternative set of configuration values which set or override default values. Using a profile, you can customize a build for different environments. Profiles are configured in the pom. xml and are given an identifier.


2 Answers

Edit, complete rewrite, as i understand the question now.

See this forum post:

profile activation is based on SYSTEM properties. you cannot activate profiles based on properties defined in your pom you cannot activate profiles based on system properties defined after the build plan has started execution

like image 52
moritz Avatar answered Sep 22 '22 21:09

moritz


What about using an activation like this

    <profile>
        <id>gwt</id>
        <activation>
            <file>
                <exists>uses-gwt.marker</exists>
            </file>
        </activation>

and adding the file 'uses-gwt.marker' into source control, right next to pom.xml. That gives all developers the same state and sort of allows an aspect-oriented pom. we're using this technique in the parent pom and put hte marker files in the childs svn. Not ideal, but works.

like image 6
Dr. Max Völkel Avatar answered Sep 21 '22 21:09

Dr. Max Völkel