Using common/default properties with multi-environment resource filtering?

274 Views Asked by At

I have a Maven project with the following properties file structure:

./clientA/
    dev.properties
    staging.properties
    production.properties
./clientB/
    dev.properties
    staging.properties
    production.properties

and so forth and so forth.

90% of the properties are all the same across the clients within the same environment (e.g. dev props on clientA and clientB are usually all the same). The properties that are the same are not, however, guaranteed to be the same across every client.

What I would like to do is create a common.[dev|staging|production].properties files at the root level, move all common properties there, then, as needed, override the common properties at the client properties files, but that doesn't appear to be supported by Maven, e.g. I can't define the same property in two properties files used for filtering, because Maven uses the value only on the first properties file processed.

How would I achieve the same functionality in Maven? Is there another way to solving this issue? Or is it not possible?

Here's what I would like to do:

common.dev.properties:
    foo=bar

clientA/dev.properties
     foo=snafu
     custom.prop=clientA Value

clientB/dev.properties
     custom.prop=clientB Value

Filtered values should be:

clientA:
    foo=snafu
    custom.prop=clientA Value

clientB:
    foo=bar
    custom.prop=clientB Value

Instead of that what happens currently is:

clientA:
    foo=bar  (i.e. the common.dev.properties foo property value can not be overriden)
    custom.prop=clientA Value

clientB:
    foo=bar
    custom.prop=clientB Value

Resources:

src/main/resources/test.properties
    foo=${foo}
    custom.prop=${custom.prop}

Resources-plugin config

<build>
    <filters>
        <filter>${basedir}/env/common.properties</filter>
        <filter>${basedir}/env/${client.name}/${env}.properties</filter>
    </filters>
<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-resources-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <encoding>UTF-8</encoding>
            </configuration>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${basedir}/target/classes</outputDirectory>
            <resources>
                            <resource>
                                <filtering>true</filtering>
                                <directory>src/main/resources</directory>
                            </resource>
                        </resources>
            </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
0

There are 0 best solutions below