严格执行两个Maven配置文件之一 [英] Enforce exactly one of two Maven profiles

查看:99
本文介绍了严格执行两个Maven配置文件之一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Maven项目,该项目定义了两个单独的配置文件developerrelease(请确保在此处找到了偏移).我想随时激活这两个配置文件之一,但不要同时激活.如果两者都被激活,则此构建没有意义,应该会失败.如果两者均未激活,则此构建也没有意义,应该会失败.

I have a Maven project that defines two separate profiles, developer and release (surely you get the drift, here). I want one of these two profiles to be activated at any time, but never both. If both are somehow activated, this build makes no sense and should fail. If neither is activated, this build also makes no sense and should fail.

我敢肯定,我可以编写一些自定义插件代码来实现这一目标,我很可能最终会采用这种方式,但是我对使用POM配置实现这一目标很感兴趣(可以使用来自Maven Central的现有插件) ).

I'm sure I can write some custom plugin code to achieve this, and I might very well end up going that way, but I'd be interested in achieving this using POM configuration (could be using existing plugins from Maven Central).

应该可以使用-P(--activate-profiles)激活插件,因此通过属性的<activation>将不是有效的解决方案.使用activeByDefault的解决方案也不是有效的,因为activeByDefault通常被称为陷阱,不可靠(而且我们实际上可能会激活其他配置文件,因此使activateByDefault无法使用).

It should be possible to activate plugins using -P (--activate-profiles) so <activation> through properties would not be a valid solution. Solutions using activeByDefault would not be valid either, since activeByDefault is generally known as a pitfall, unreliable (and we may in fact activate other profiles, thus rendering activateByDefault unusable).

非常感谢您的建议.

推荐答案

最简单的解决方案是使用

The simplest solution for this kind of problem would be to use the maven-enforcer-plugin which exactly has such a rule to force to activate at least one of two or more profiles.

很遗憾,requireActiveProfile当前具有 bug .但是目前正在为解决该问题的新版本做准备.

Unfortunately the requireActiveProfile has currently a bug. But currently a preparation for a new release is on going which solves this.

更新上述错误已在1.4版(2015年发布)中得到修复.

Update The bug mentioned above has been fixed in release 1.4 (which was released in 2015).

这篇关于严格执行两个Maven配置文件之一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆