问题
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.
Is this even possible?
<dependency>
<groupId>XYZ</groupId>
<artifactId>B</artifactId>
<version>${project.version}</version>
<type>jar</type>
<scope>test</scope>
</dependency>
Both projects are under my controll.
Thanks for your advice
回答1:
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>
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>
Changing 'type' to test-jar allows you to access test classes from that dependency.
来源:https://stackoverflow.com/questions/29653914/how-can-i-reference-unit-test-classes-of-a-maven-dependency-in-my-java-project