Maven程序集:添加相同工件的不同版本 [英] Maven assembly : add different version of the same artifact
问题描述
我使用maven程序集插件创建我的应用程序存档。
我的pom中存在的所有依赖项都没有任何问题。
I create my application archive with the maven assembly plugin. All the dependency present in my pom are included without any problem.
现在我需要包含两个或更多版本的相同工件。
Now I need to include two or more version of the same artifact.
如果在我的pom中我放了
If in my pom I put
<dependencies>
[...]
<dependency>
<groupId>db.test</groupId>
<artifactId>my-model</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>db.test</groupId>
<artifactId>my-model</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
源代码依赖性解析器删除旧版本,只有1.1.0打包在存档中
Of source the dependenvcy resolver remove the old version and only the 1.1.0 is packaged in the archive
我尝试使用程序集xml描述符文件包含jar。我没有找到任何解决方案。
I try to include the jar by using assembly xml descriptor file. And I didn't find any solution.
一个可能的解决方案是手动将所有需要的model.jar放入一个文件夹中并告诉程序集将其复制到存档。但我正在寻找一个更可配置的解决方案。
A possible solution will be to manually put all the needed model.jar inside a folder and tell the assembly to copy it in the archive. But I'm looking for a more configurable solution.
任何想法?
推荐答案
我通过使用maven-dependency-plugin复制已解析的pom依赖项和其他jar来找到解决方案。
I found a solution by using maven-dependency-plugin to copy resolved pom dependencies and additional jar.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<includeScope>runtime</includeScope>
</configuration>
</execution>
<execution>
<id>copy-model</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>my.test.pkg</groupId>
<artifactId>my-model</artifactId>
<classifier>server</classifier>
<version>1.0.3</version>
<type>jar</type>
</artifactItem>
<artifactItem>
<groupId>my.test.pkg</groupId>
<artifactId>my-model</artifactId>
<classifier>server</classifier>
<version>1.1.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
现在我只需添加我的程序集中的以下行xml
Now I just have to add the following lines in my assembly xml
<fileSet>
<directory>${project.build.directory}/lib</directory>
<outputDirectory>/lib</outputDirectory>
<filtered>false</filtered>
<includes>
<include>*.jar</include>
</includes>
<fileMode>0600</fileMode>
</fileSet>
这篇关于Maven程序集:添加相同工件的不同版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!