Mah*_*ror 6 java junit pom.xml maven
我需要在项目A的测试包src/test/java中引用项目B中的一些JUnit测试(src/test/java),而B是A的maven依赖项.
这甚至可能吗?
<dependency>
<groupId>XYZ</groupId>
<artifactId>B</artifactId>
<version>${project.version}</version>
<type>jar</type>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
这两个项目都在我的控制之下.
谢谢你的建议
小智 10
你在项目B中的pom需要包含这个插件:
<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>
Run Code Online (Sandbox Code Playgroud)
然后,您可以从项目A访问它,如下所示:
<dependency>
<groupId>XYZ</groupId>
<artifactId>B</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
将"type"更改为test-jar允许您从该依赖项访问测试类.