Maven: How do I activate a profile from command line?
Both commands are correct :
mvn clean install -Pdev1
mvn clean install -P dev1
The problem is most likely not profile activation, but the profile not accomplishing what you expect it to.
It is normal that the command :
mvn help:active-profiles
does not display the profile, because is does not contain -Pdev1
. You could add it to make the profile appear, but it would be pointless because you would be testing maven itself.
What you should do is check the profile behavior by doing the following :
- set
activeByDefault
totrue
in the profile configuration, - run
mvn help:active-profiles
(to make sure it is effectively activated even without-Pdev1
), - run
mvn install
.
It should give the same results as before, and therefore confirm that the problem is the profile not doing what you expect.
Activation by system properties can be done as follows
<activation>
<property>
<name>foo</name>
<value>bar</value>
</property>
</activation>
And run the mvn build with -D to set system property
mvn clean install -Dfoo=bar
This method also helps select profiles in transitive dependency of project artifacts.
I have encountered this problem and i solved mentioned problem by adding -DprofileIdEnabled=true
parameter while running mvn cli command.
Please run your mvn cli command as : mvn clean install -Pdev1 -DprofileIdEnabled=true
.
In addition to this solution, you don't need to remove activeByDefault settings in your POM mentioned as previouses answer.
I hope this answer solve your problem.