从 Maven 中的测试资源复制空目录

Copy empty directory from test resources in Maven

基于此 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>

但也无济于事。

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

感谢您的帮助或建议。

终于解决了!

问题是元素 <includeEmptyDirs> 在插件部分的位置不对。它应该是 插件配置 的一部分,而不是 执行配置 的一部分。

另外,我将 copy-test-resource 的目标更改为 testResources,将 outputDirectory 更改为 ${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>