I\'m trying to activate a maven profile using a property defined inside pom.xml
:
[...]
Now it should work. You can overwrite the "run.it" property in your pom.xml and it will be picked up for profile activation.
I am not sure if this is a bug or a feature.
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.
I think your question is similar to this one.
Activation of maven profile based on multiple properties
As mentioned, you can activate a profile and set various properties as per your requirement and use command mvn -Prun-it
to set property to true .
<project>
[...]
[...]
<profiles>
<profile>
<id>don't-run</id>
<properties>
<run.it>false</run.it>
</properties>
[...]
</profile>
<profile>
<id>run-it</id>
<properties>
<run.it>true</run.it>
</properties>
[...]
</profile>
</profiles>
[...]
</project>
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
In recent maven versions (3.5+?) you can create a .mvn
folder at the root of your project and a file .mvn/maven.config
. In this file you can then activate profiles or set properties as you would do on the command line.
-Dactivate.myprofile=true
activate a profile directly
-Pmyprofile
Hopefully maven5 will get support for Mixins, which will probably make build settings more reusable.
As Moritz Heuser explained, profile activation is based on system properties. However, you can try something like that:
<project>
...
<properties>
<run.it>true</run.it>
</properties>
...
<profiles>
<profile>
<activation>
<activeByDefault>${run.it}</activeByDefault>
</activation>
...
</profile>
</profiles>
...
</project>
The idea is to define the activeByDefault
flag in the <properties>
.