在Maven的测试资源复制空目录

问题描述 投票:2回答:1

在此基础上comment我试图在基于Maven的项目复制从测试资源文件夹中的空目录到测试生成输出,但没有运气。我已经成功地使用maven-resource-plugin用于复制的基本资源,所以我想这样添加其他执行部分的测试资源,我pom.xml

<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.7</version>
    <executions>
        <execution>
            <id>copy-resource</id>
            <phase>package</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <includeEmptyDirs>true</includeEmptyDirs>
                <outputDirectory>${project.build.outputDirectory}</outputDirectory>
                <resources>
                    <resource>
                        <directory>src/main/resources</directory>
                    </resource>
                </resources>
            </configuration>
        </execution>
        <execution>
            <id>copy-test-resource</id>
            <phase>package</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <includeEmptyDirs>true</includeEmptyDirs>
                <outputDirectory>${project.build.testSourceDirectory}</outputDirectory>
                <resources>
                    <resource>
                        <directory>src/test/resources</directory>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>

我也试过在这样构建部分来定义它:

<testResources>
    <testResource>
        <directory>src/test/resources</directory>
    </testResource>
</testResources>

但它也没有帮助。

所有文件和非空目录被正确地复制,但空单目录没有。

感谢您的任何帮助或建议。

java maven testing pom.xml
1个回答
3
投票

最后,我解决了这个问题!

问题是,元素<includeEmptyDirs>是在插件部分错了地方。它应该是插件配置,执行配置的不属于的一部分。

此外,我改变了copy-test-resource的目标testResourcesoutputDirectory${project.build.testOutputDirectory}

所以,正确的插件部分如下:

<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.7</version>
    <configuration>
        <includeEmptyDirs>true</includeEmptyDirs>
    </configuration>
    <executions>
        <execution>
            <id>copy-resource</id>
            <phase>package</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.outputDirectory}</outputDirectory>
                <resources>
                    <resource>
                        <directory>src/main/resources</directory>
                    </resource>
                </resources>
            </configuration>
        </execution>
        <execution>
            <id>copy-test-resource</id>
            <phase>package</phase>
            <goals>
                <goal>testResources</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.testOutputDirectory}</outputDirectory>
                <resources>
                    <resource>
                        <directory>src/test/resources</directory>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>
© www.soinside.com 2019 - 2024. All rights reserved.