Different dependencies for different build profiles

久未见 提交于 2019-11-26 01:07:22

问题


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.


回答1:


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>



回答2:


Your groupId, artifactId should be tokenized in your profiles as properties and you can move your dependencies to the generic section.



来源:https://stackoverflow.com/questions/166895/different-dependencies-for-different-build-profiles

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!