如何在两个项目中的测试文件夹之间设置Maven依赖项?

mar*_*hon 8 java maven-2 unit-testing maven-3 maven

我有一个像这样的项目设置:

parent
     |_____project-a
     |_____project-b
Run Code Online (Sandbox Code Playgroud)

我想在类测试项目-B的文件夹中的项目-A的测试文件夹来解决类.

实际上,我想从主文件夹和测试文件夹中访问两个类.

这可能吗?

谢谢

art*_*tol 10

您可以使用目标test-jar构建项目A.

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>test-jar</goal>
                    </goals>
                </execution>
            </executions>               
        </plugin>       
Run Code Online (Sandbox Code Playgroud)

然后test-jar在项目B中包含它类型:

    <dependency>
        <groupId>com.example</groupId>
        <artifactId>project-a</artifactId>
        <type>test-jar</type>
        <version>1.0-SNAPSHOT</version>
        <scope>test</scope>
    </dependency>
Run Code Online (Sandbox Code Playgroud)


小智 5

由于测试文件夹的内容未包含在项目的目标中,因此无法在外部使用.我认为最好的方法是将公共类移动到像'project-testcommons'这样的项目中,并在项目-a和项目-b中使用'test'范围.