设置 我正在打包一个包含许多遗留jar依赖关系的WAR(为了保持这个简单,它们不可能被部署的WAR更改或排除)。
问题 包括其中两个罐子中的任何一个或两个都会在测试时产生不可避免的错误。如果我完全排除了依赖项,测试会很愉快地通过,但WAR将缺少它所需的真实运行时类。
希望 Maven2提供编译,测试,运行时,系统和提供的范围。可悲的是,这些都不是included in the assembly but kept off the test classpath。我希望我完全缺少一些在依赖管理功能中处理这种情况的明显方法。
恐惧 我将不得不使用程序集插件将这些问题jar复制到目标中。我不想让依赖管理系统将jar中的jar文件复制到目标中,因为我不想在内部存储库之外管理这些jar。
思考?备择方案?
答案 0 :(得分:2)
当然,我发现在发布问题之后,我会遇到一个潜在的解决方案。似乎依赖插件的复制目标可以处理这个问题。现在就试试这个:http://maven.apache.org/plugins/maven-dependency-plugin/usage.html
编辑:原来这样可以满足我的需求,下面的代码段:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>copy</goal>
</goals>
</execution>
</executions>
<configuration>
<artifactItems>
<artifactItem>
<groupId>group</groupId>
<artifactId>artifact</artifactId>
<version>version</version>
<type>jar</type>
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/lib</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</plugin>
答案 1 :(得分:0)
将测试类从jar文件中拆分到一个单独的jar中,该jar仅用于测试,并添加对具有遗留依赖项的jar依赖项的排除。