如何在Java项目中引用Maven依赖项的单元测试类? [英] How can I reference unit test classes of a maven dependency in my java project?
本文介绍了如何在Java项目中引用Maven依赖项的单元测试类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在项目A的测试包src/test/java中引用项目B的一些JUnit测试(src/test/java),而B是A的依赖者.
I need to reference some JUnit Tests (src/test/java) from project B in the test package src/test/java of project A whereas B is a maven dependecy of A.
这有可能吗?
<dependency>
<groupId>XYZ</groupId>
<artifactId>B</artifactId>
<version>${project.version}</version>
<type>jar</type>
<scope>test</scope>
</dependency>
两个项目都在我的控制之下.
Both projects are under my controll.
感谢您的建议
推荐答案
您在项目B中的pom需要包括此插件:
Your pom in project B needs to include this plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
然后,您可以像这样从项目A访问它:
Then, you can access it from project A like this:
<dependency>
<groupId>XYZ</groupId>
<artifactId>B</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
将类型"更改为test-jar允许您从该依赖项访问测试类.
Changing 'type' to test-jar allows you to access test classes from that dependency.
这篇关于如何在Java项目中引用Maven依赖项的单元测试类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文