小编Mat*_*roz的帖子

如何使maven从/ src/test/resources而不是/ src/main/resources获取依赖项目的资源?

我搜索了论坛,找到了我的问题的答案,但我无法找到它.我的问题是:

我有两个项目:ProjectA和ProjectB.ProjectB使用ProjectA.在ProjectA中,我有两个文件夹:/ src/main/resources和/ src/test/resources.在ProjectB中我运行:mvn clean install.我想,在测试阶段,ProjectB中的类使用/ src/test/resources中的资源而不是/ src/main/resources.

这就是我尝试过的:http: //www.waltercedric.com/java-j2ee-mainmenu-53/361-maven-build-system/1349-maven-reusing-test-classes-across-multi-modules-projects. HTML

它类似于我的问题,但是在为ProjectA配置test-jar目标之后,ProjectB仍然运行测试,ProjectA中的类使用/ src/main/resources中的属性而不是/ src/test/resources.

我在ProjectA中的pom.xml看起来像:

<project ...>
    <parent>
        ...
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>ProjectA</artifactId>
    <packaging>jar</packaging>

    <dependencies>
        ...
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
                <filtering>true</filtering>
            </testResource>
        </testResources>

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

在ProjectB中,我的pom.xml看起来像:

<project ...>
    <parent>
        ...
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>ProjectB</artifactId>
    <packaging>jar</packaging>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins> …
Run Code Online (Sandbox Code Playgroud)

resources dependencies jar maven

13
推荐指数
1
解决办法
3万
查看次数

标签 统计

dependencies ×1

jar ×1

maven ×1

resources ×1