The maven profiles manual is confusing when it discusses activating maven profiles via environment variables. The examples do not work on Ubuntu, so it’s a tough starting point.
Given that you have set an environment variable in bash or system wide using /etc/environment.
e.g.
set RUN_MY_SPECIAL_TESTS=true
Wrong way:
<profiles>
<profile>
<activation>
<property>
<name>RUN_MY_SPECIAL_TESTS</name>
<value>true</value>
</property>
</activation>
...
</profile>
</profiles>
Right way:
<profiles>
<profile>
<activation>
<property>
<name>env.RUN_MY_SPECIAL_TESTS</name>
<value>true</value>
</property>
</activation>
...
</profile>
</profiles>
Right way, if you only care that an environment variable exists. Not what it’s value is:
<profiles>
<profile>
<activation>
<property>
<name>env.RUN_MY_SPECIAL_TESTS</name>
</property>
</activation>
...
</profile>
</profiles>
These are your friends when configuring your profiles and env properties:
mvn help:active-profiles
mvn help:effective-pom
Note, if you activate 2 or more profiles that all try to set the same property, the last profile in the list will be the winner.
Hope this helps.
Thank you so much for this blog. I was using ${env.TOMCAT_HOME} in a property file and it seemed to work just fine on my Windows machine, but not on my Mac. When I added the activiation property as you defined above, then maven properly filtered and replaced the value with the environment variable.
Thank you, it works for me!!!
I think your prefixing the environment variable with env. is related to your OS and not something coming from Maven in fact. On my Linux box it was in the way. I had to not prefix it.
Thanks for your post. It saved my day.
Thanks!
Thank you very much for the env. thing, I was hitting my head against the wall for several hours trying to make my docker profile activate when DOCKER_HOST environment property is available
Thank you!
Helped a lot