使用maven-jar-plugin
插件的目标(请参阅here),在使用test-jar
目标的maven项目之间共享通用测试代码是一个明确的解决方案。在maven项目之间共享测试资源
我需要对测试资源做类似的事情,特别是我希望在测试期间项目B的类路径中可以使用项目A的测试资源。
项目A的一个需要声明:
<!-- Package and attach test resources to the list of artifacts: -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<jar destfile="${project.build.directory}/test-resources.jar">
<fileset dir="${project.basedir}/test-resources" />
</jar>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.directory}/test-resources.jar</file>
<type>jar</type>
<classifier>test-resources</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
而在B项目将是正常的依赖性:
<dependency>
<groupId>myproject.groupId</groupId>
<artifactId>myartifact</artifactId>
<version>1.0-SNAPSHOT</version>
<classifier>test-resources</classifier>
<scope>test</scope>
</dependency>
问:是否应该在所有情况下工作吗?没有maven-antrun-plugin
(使用更多'轻量级'插件)是否可以打包资源?
似乎还有需要增强测试资源的远程资源插件 - http://maven.apache.org/plugins/maven-remote-resources-plugin/index.html – cetnar 2010-02-11 21:35:01
@centar:感谢有趣的插件信息,但是,你所说的是有点偏离主题:) – 2010-02-15 11:09:09