我使用maven汇编插件创建我的应用程序存档。存在于我的pom中的所有依赖项都包含在内,没有任何问题。
现在,我需要包含同一工件的两个或更多版本。
如果我在我的pom里
<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
我尝试通过使用程序集xml描述符文件来包含jar。我没有找到任何解决方案。
一种可能的解决方案是手动将所有需要的model.jar放在一个文件夹中,并告诉程序集将其复制到归档中。但我正在寻找一种更具可配置性的解决方案。
有什么想法吗?
发布于 2010-11-30 22:11:14
我找到了一个解决方案,使用maven-dependency-plugin复制已解析的pom依赖项和附加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中添加以下几行
<fileSet>
<directory>${project.build.directory}/lib</directory>
<outputDirectory>/lib</outputDirectory>
<filtered>false</filtered>
<includes>
<include>*.jar</include>
</includes>
<fileMode>0600</fileMode>
</fileSet>
发布于 2010-11-30 18:25:24
Maven假设一次拥有一个模块的多个版本没有任何意义。它假定较新的版本将替换旧版本。如果不是,那么它就不是同一个模块。我建议你给新的模块一个不同的名字,并确保它有不同的包,以避免选择一个随机的模块。
总的来说,Maven试图鼓励好的应用程序设计,并故意让它认为是坏主意的事情变得困难。
发布于 2010-11-30 20:58:38
另一个丑陋的解决方案可能是使用WAR文件覆盖,利用此机制在应用覆盖时不关注组件JAR文件的版本这一事实。
https://stackoverflow.com/questions/4312553
复制相似问题