This is somewhat untested, however I've used the properties-maven-plugin for a similar use case where I want to load a file that may or may not exist. Might not be a totally working
answer, but I hope it gives you ideas.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<id>load-filters</id>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${basedir}/src/main/props/${environment}-${flavor}.properties</file>
</files>
<quiet>true</quiet> <!-- important! -->
</configuration>
</execution>
</executions>
</plugin>
The "quiet" part tells the plugin not to fail the build if the file doesn't exist; it will simply log a message and move on. If the file exists, the properties are loaded as Project properties.
When the resources
plugin executes, it filters using
System properties, project properties, and filter properties files specified in the POM build/filters section
so the properties will be applied to the resources without any further config. You won't need to specify <filters>
in the resources plugin.
The above covers the 'ignore' case. It may get a little trickier if you want to provide a fallback. I am not sure how the properties plugin interacts with
<filters>
<filter>${basedir}/src/main/props/base.properties</filter>
</filters>
for example - which would take precedence, the loaded project properties, or the filter properties? I'd be tempted to try something like this:
<properties>
<prop1>defaultValue</prop1>
<prop2>anotherDefaultValue</prop2>
</properties>
and then have the loaded files override the values as needed. I believe this works.
You might also check out the code for the properties plugin to see which properties take precedence if multiple files specifying the same property are loaded, then configure the plugin to load both files in the order that results in the behavior desired.