您的消费者项目取决于您的数据项目,因此我们很高兴必须在消费者之前构建数据。结果,使用[注释中](http://codingdict.com/questions/109626建议的技术,我将确保您的Data项目包含您希望共享的所有测试代码,并配置POM以生成测试JAR:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.2</version> <executions> <execution> <goals> <goal>test-jar</goal> </goals> </execution> </executions></plugin>
然后,您的Consumer项目将同时依赖于正常的Data JAR工件以及其他
test-jar工件,当然还有测试范围:
<dependency> <groupId>com.foo</groupId> <artifactId>data</artifactId> <version>1.0</version> <type>test-jar</type> <scope>test</scope></dependency>
我已经在很多场合使用过这种方法,并且效果很好。



