bmargulies gave the answer, but let me fill in some details.
<testresources>
can be added to the <build>
node of the project's POM, like this:
<testResources>
<testResource>
<directory>${project.basedir}/src/test/java</directory>
</testResource>
</testResources>
That copies everything in src/test/java
-- including the .java
source code, which we don't want.
It also (as bmargulies only hinted at) overrides and replaces the default <testResources>
setting in the standard parent POM that all other POM inherit from (unless that inheritance is changed). The standard parent copies src/test/resources
, so by overriding that, we don't get that copied as usual, which we don't want. (In particular, my whole reason for doing this is to use unitils, which wants the unitils.properties
file copied -- and that's (for me, anyway) in src/test/resources
.
So we re-add src/test/resources
:
<testResources>
<testResource>
<directory>${project.basedir}/src/test/java</directory>
</testResource>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>
That copies in the order listed, so that for files that exist in both /src/test/java
(and subdirectories) and in /src/test/resources
(and subdirectories), the src/test/resources
version is the one that ends up in test-classes
.
Now we just need to not copy the .java
files:
<testResources>
<testResource>
<directory>${project.basedir}/src/test/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>
mvn test-compile
withmaven-resources-plugin:testResources
bound to theprocess-test-resources
phase andmaven-compiler-plugin:testCompile
bound to thetest-compile
phase. I adapted the question acordingly. – Weasand