Profile x will be the the only active profile when you call mvn ... -P x
. Reason from the maven documentation:
Profiles can be explicitly specified using the -P CLI option.
This option takes an argument that is a comma-delimited list of profile-ids to
use. When this option is specified, no profiles other than those specified in
the option argument will be activated.
Here’s a workaround:
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>!specific</name>
</property>
</activation>
</profile>
<profile>
<id>specific</id>
<activation>
<property>
<name>specific</name>
</property>
</activation>
</profile>
<profile>
<id>x</id>
<activation>
<property>
<name>x</name>
</property>
</activation>
</profile>
<profile>
<id>y</id>
<activation>
<property>
<name>y</name>
</property>
</activation>
</profile>
</profiles>
The commands:
mvn ... // default
mvn ... -Dspecific // specific Profile (no default!)
mvn ... -Dx // default + x
mvn ... -Dx -Dy // default + x + y
mvn ... -Dx -Dspecific // x + specific Profile (no default!)
mvn ... -Dx -Dspecific -Dy // x + specific Profile + y (no default!)
Execute mvn ... help:active-profiles
to get the list of the ids of active profiles.