tags:

views:

45

answers:

1

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:

maven install maven -Pdev install maven -Ptest install maven -Pprod install

In case someone writes for example maven -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.

+2  A: 

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.

cetnar