I would like to have my Java project using Maven set up so that when developing locally and when running unit tests, resources are taken from the standard src/main/resources
and src/test/resources
directories, while when applying a profile the resources are overwritten with deployment-specific ones. Ideally, the profile specific resources will be a subset of the full resources, so the process should work by first writing the regular resources, then applying the profile specific ones on top of the first.
My directory layout is the standard one, with the profiles resources under src/main/env/{profile}
.
I managed to do this using multiple stanzas under build
/resources
:
<profiles>
<profile>
<id>dev</id>
<activation><activeByDefault>true</activeByDefault></activation>
<properties>
<targetEnv>dev</targetEnv>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<targetEnv>test</targetEnv>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<targetEnv>prod</targetEnv>
</properties>
</profile>
</profiles>
<build>
<resources>
<resource>
<directory>src/main/env/${targetEnv}</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<build>
This is working, however, my first attempt was with the two resource directories ordered in the opposite way (first the regular directory, the the profile specific one), in a way to match the overwriting process. Instead, it was overwriting the profile specific files with the regular ones.
Does Maven guarantee an order for the stanzas under build
/resources
at all?