Maven - 我可以在配置文件定义中引用配置文件ID吗? [英] Maven - Can I reference profile id in profile definition?

查看:228
本文介绍了Maven - 我可以在配置文件定义中引用配置文件ID吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 pom.xml 中设置了个人资料,如下所示:

I've set profiles in a pom.xml, like shown as follows:

<profile>
<id><em>profileId1</em></id>
    <build>
        <filters>
            <filter>src/main/filters/<em>profileId1</em>.properties</filter>
        </filters>
// rest of the profile 
</profile>
<profile>
<id><em>profileId2</em></id>
    <build>
        <filters>
            <filter>src/main/filters/<em>profileId2</em>.properties</filter>
        </filters>
// rest of the profile
</profile>

问题:

有没有办法从所有配置文件中提取这个部分,这样就不需要为每个配置文件重复它(并且可能拼错它)?

Is there any way to extract this piece from all the profiles, so that there is no need to repeat it for every profile (and possibly misspell it)?

推荐答案

使用maven 2.2.1及更高版本,我可以使用以下方式获取第一个活动配置文件的ID:

With maven 2.2.1 and later, I was able to get the ID of the first active profile using:

${project.activeProfiles[0].id}

当然这失败了如果没有至少一个活动配置文件。

Of course this fails if there is not a least one active profile.

使用

${project.profiles[0].id}

按照Pascal的建议为我工作。

as suggested by Pascal did not work for me.

提示:在调查此问题时,我真的开始喜欢 mvn help:evaluate

Hint: While investigating this, I really started to love mvn help:evaluate.

这篇关于Maven - 我可以在配置文件定义中引用配置文件ID吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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