开发者

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 f开发者_JAVA技巧ail. 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜