Martin Vrábel
Martin Vrábel

Reputation: 900

Copy empty directory from test resources in Maven

Based on this comment I am trying to copy an empty directory from test resources folder in Maven based project to the test build output but with no luck. I have already been successfully using maven-resource-plugin for copying basic resources so I tried to add another execution part for test resources like this to my 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>

I also tried to define it in build section like this:

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

but it also didn't help.

All files and non-empty directories gets correctly copied but the single empty directory doesn't.

Thanks for any help or advice.

Upvotes: 4

Views: 2365

Answers (1)

Martin Vr&#225;bel
Martin Vr&#225;bel

Reputation: 900

Finally, I solved it!

The problem is that element <includeEmptyDirs> was in the wrong place in the plugin section. it should be a part of plugin configuration, NOT part of execution configuration.

Also I changed goal of copy-test-resource to testResources and outputDirectory to ${project.build.testOutputDirectory}

So the correct plugin section is following:

<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>

Upvotes: 4

Related Questions