How can I reference unit test classes of a maven dependency in my java project? [duplicate]

☆樱花仙子☆ 提交于 2019-12-23 09:16:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!