不同构建配置文件的不同依赖项 [英] Different dependencies for different build profiles

查看:36
本文介绍了不同构建配置文件的不同依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于不同的配置文件,maven pom.xml 文件中是否可以有一组不同的依赖项?

例如

mvn -P 调试mvn -P 释放

我想在一个配置文件中选择一个不同的依赖 jar 文件,该文件具有相同的类名和相同接口的不同实现.

解决方案

引用 Maven 文档这个:

配置文件元素包含一个可选的激活(配置文件触发器)和一组对 POM 进行的更改(如果该配置文件已被激活).例如,为测试环境构建的项目可能指向与最终部署不同的数据库.或者可以根据使用的 JDK 版本从不同的存储库中提取依赖项.

(重点是我的)

只需将 release 配置文件的依赖项放在配置文件声明本身中,并对 debug 执行相同操作.

<前><个人资料><个人资料><id>调试</id>…<依赖项><依赖>…</dependency></依赖项>…</个人资料><个人资料><id>发布</id>…<依赖项><依赖>…</dependency></依赖项>…</个人资料></个人资料>

Is it possible to have a different set of dependencies in a maven pom.xml file for different profiles?

e.g.

mvn -P debug
mvn -P release

I'd like to pick up a different dependency jar file in one profile that has the same class names and different implementations of the same interfaces.

解决方案

To quote the Maven documentation on this:

A profile element contains both an optional activation (a profile trigger) and the set of changes to be made to the POM if that profile has been activated. For example, a project built for a test environment may point to a different database than that of the final deployment. Or dependencies may be pulled from different repositories based upon the JDK version used.

(Emphasis is mine)

Just put the dependency for the release profile inside the profile declaration itself and do the same for debug.

<profiles>
    <profile>
        <id>debug</id>
        …
        <dependencies>
            <dependency>…</dependency>
        </dependencies>
        …
    </profile>
    <profile>
        <id>release</id>
        …
        <dependencies>
            <dependency>…</dependency>
        </dependencies>
        …
    </profile>
</profiles>

这篇关于不同构建配置文件的不同依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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