maven 同一个模块加载多个版本的方法

实际上属于一个小窍门,但是并不推荐使用,这种方法,比较适合,我们需要开发插件化应用

参考格式

以下格式就可以支持同一个模块的多版本加载打包了

<dependency>
    <groupId>com.dalongdemo</groupId>
    <artifactId>moduleapp</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
    <groupId>com.dalongdemo..</groupId>
    <artifactId>moduleapp</artifactId>
    <version>2.0-SNAPSHOT</version>
</dependency>

简单原理说明

实际上是利用了maven 对于. 的特殊处理,原文如下
The dots are replaced by OS specific directory separators (such as '/' in Unix) which becomes a relative directory structure from the base repository. In the example given, the org.codehaus.mojo group lives within the directory $M2_REPO/org/codehaus/mojo

说明

基于此方法我们可以解决webjars 多版本maven 包加载的问题,属于一个hack 方法了,当然我们也可以利用构建工具,在一同的阶段进行处理了,比如使用
ant maven 插件,通过copy 的模式进行处理,方法很多

参考资料

https://stackoverflow.com/questions/24962607/multiple-versions-of-the-same-dependency-in-maven
https://maven.apache.org/pom.html#maven-coordinates

posted on 2022-02-07 13:06  荣锋亮  阅读(441)  评论(0编辑  收藏  举报

导航