tputkonen
tputkonen

Reputation: 5729

Maven2: is there a way to make the build fail in case of unknown profile parameter?

We have three different maven2 profiles: prod, dev and test. One should be able to build with either one of those three profiles, or without any profile. In other words, following commands are acceptable:

mvn install
mvn -Pdev install
mvn -Ptest install
mvn -Pprod install

In case someone writes for example mvn -Ppord install, the build must fail. Is this possible to do?

P.s. I'm aware of http://maven.apache.org/enforcer/enforcer-rules/requireProperty.html but it seems that with require property it would not be possible to allow building without profile.

Upvotes: 2

Views: 308

Answers (1)

cetnar
cetnar

Reputation: 9415

I think it should be possible with writing custom enforcer rule. If you'll look at this example you'll see:

RuntimeInformation rti = (RuntimeInformation) helper.getComponent( RuntimeInformation.class );

this line gives you information about current runtime, following get MavenProject and active profiles list

MavenProject project = (MavenProject) helper.evaluate( "${project}" );
List profiles = new ArrayList( project.getActiveProfiles() );

If list of active profiles will be insuficient, you can get all profiles - example of this code can be found in AllProfilesMojo.java from helper plugin.

Upvotes: 2

Related Questions