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

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

问题描述

是否可以在maven pom.xml文件中为不同的配置文件设置一组不同的依赖项?

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

例如

mvn -P debug
mvn -P release

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

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.

推荐答案

引用 Maven文档

配置文件元素包含可选激活(配置文件触发器)以及在激活该配置文件后对POM进行的更改集。例如,为测试环境构建的项目可能指向与最终部署不同的数据库。 或者可以根据使用的JDK版本从不同的存储库中提取依赖关系
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.

(强调是我的)

只需将 release 配置文件的依赖项放在配置文件声明本身中,并对 debug

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天全站免登陆