在Maven中创建独家配置文件 [英] Creating exclusive profiles in maven

查看:140
本文介绍了在Maven中创建独家配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个带有特定于平台的配置文件的pom(例如linux 32bit,windows 64 bit等).此外,我将其设置为自动选择调用者的平台作为默认平台.

I currently have a pom with platform specific profiles (e.g. linux 32bit, windows 64 bit, etc...). Additionally, I have set it up to automatically choose the invoker's platform as a default.

现在,假设我在linux 32机器上:我也想通过调用mvn -Pwin64 pakage为win64进行构建,但是这样做时,会同时激活linux32和win64配置文件.我尝试使用activeProfiles和使用ativation标记激活本地平台配置文件.问题是-P不能禁用文档中所述的所有其他配置文件:

Now, assume I am in a linux 32 machine: I also want to build for win64 by invoking mvn -Pwin64 pakage but in doing so, both the linux32 and win64 profiles get activated. I have tried activating the local platform profile with activeProfiles and using ativation tags. The trouble is that -P does not disable all other profiles as explained in the documentation:

此选项采用的参数是逗号分隔的列表 要使用的个人资料ID.指定此选项后,没有其他配置文件 超出了option参数中指定的值.

This option takes an argument that is a comma-delimited list of profile-ids to use. When this option is specified, no profiles other than those specified in the option argument will be activated.

我了解这个错误吗?您将如何处理?

Am I understanding this wrong? How would you handle this?

注意:我知道我可以运行mvn -P-linux32,win64,但是仅在linux32平台上有效,并且任何错误都可能导致带有重复类的build肿构建.

Note: I know I could run mvn -P-linux32,win64 but that is only valid on linux32 platforms, and any mistakes may result in a bloated build with duplicate classes.

谢谢!

推荐答案

个人资料文档:

从Maven 3.0开始,还可以基于settings.xml中活动配置文件的属性来激活POM中的配置文件.

As of Maven 3.0, profiles in the POM can also be activated based on properties from active profiles from the settings.xml.

将带我尝试以下解决方案.每个开发人员都在他的settings.xml文件中将其默认平台定义为属性,并在需要时在cmdline上覆盖它.

Would lead me to try the solution below. Each developer defines his default platform as a property in his settings.xml file and overrides it on the cmdline if needed.

开发人员的settings.xml

<profile>
    <id>platform-config</id>
    <property>
        <name>build.platform</name>
        <value>win32</value>
    </property>
</profile>
....
<activeProfiles>
    <activeProfile>platform-config</activeProfile>
</activeProfiles>

项目的pom.xml

<project>
...
<profiles>
    <profile>
        <id>win32</id>
        <activation>
            <property>
                <name>build.platform</name>
                <value>win32</value>
            </property>
        </activation>
        ...
    </profile>
    <profile>
        <id>linux32</id>
        <activation>
            <property>
                <name>build.platform</name>
                <value>linux32</value>
            </property>
        </activation>
        ...
    </profile>
</profiles>

然后,mvn install应该激活win32配置文件,因为build.platform属性的默认值为win32,而mvn install -Dbuild.platform=linux32将覆盖默认属性设置,而是使用Linux配置文件.

Then, mvn install should activate the win32 profile because the default value for the build.platform property is win32, while mvn install -Dbuild.platform=linux32 will override the default property setting and use the Linux profile instead.

这篇关于在Maven中创建独家配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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