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

时间:2015-06-03 22:49:45

标签: java maven testing pom.xml

基于此comment我正在尝试将基于 Maven 项目的测试资源文件夹中的空目录复制到测试构建输出但没有运气。我已成功使用 window.onfocus 复制基本资源,因此我尝试将此类测试资源的其他执行部分添加到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>

但它也没有帮助。

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

感谢您提供任何帮助或建议。

1 个答案:

答案 0 :(得分:3)

最后,我解决了!

问题是元素<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>