I would agree that this question is somewhat weird.
Let's say I have a maven project which has following profiles.
$ mvn help:all-profiles
Profile Id: profile1 (...)
Profile Id: profile2 (...)
Profile Id: profile3 (...)
$
Is there anyway that I can force to fail without any specific profile selection?
$ mvn clean package
FAIL
$ mvn -Pprofile1 clean package
SUCCESS
$ mvn -Pprofile2 clean package
SUCCESS
$ mvn -Pprofile3 clean package
SUCCESS
$
UPDATE(with personal conclusion)
Again, this question is not a good one even if there would be someone who has the exact problem.
The original intention is charging the responsibility who build the project with explicit profile selection.
Both the comment of @khmarbaise and the answer of @AngeloNeuschitzer are OK to solve the problem.
But here I think I should update what I ended up with.
As @khmarbaise commented, we can do like this.
$ mvn help:all-profiles
Profile Id: development
Profile Id: integration
Profile Id: staging
Profile Id: production (active by default)
$ mvm clean package
Profile -> production
$ mvn -Pdevelopment clean package
Profile -> development
One of original problem that I faced is what if anyone build for development and deploy to production, accidentally, by fault?
I choose the production profile active by default for this case. Using the classifier is one of additional method I can use.
You can use the maven-enforcer-plugin to fail a build when no profile is active. It's much cleaner than having a special profile that always fails (the code in the accepted answer even looks kind of malicious).
Use the build-in requireActiveProfile rule with <all>false</all> to enforce that at least one profile is active:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M2</version>
<executions>
<execution>
<id>enforce-first-or-second-profile-is-active</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireActiveProfile>
<profiles>first,second</profiles>
<all>false</all>
</requireActiveProfile>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
You can even add a custom message in the configuration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With