How to share common properties among several maven projects?

What you can do is to use the Properties Maven plugin. This will let you define your properties in an external file, and the plugin will read this file.

With this configuration :

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>properties-maven-plugin</artifactId>
            <version>1.0-alpha-1</version>
            <executions>
                <execution>
                    <phase>initialize</phase>
                    <goals>
                        <goal>read-project-properties</goal>
                    </goals>
                    <configuration>
                        <files>
                            <file>my-file.properties</file>
                        </files>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

and if you have, in your properties file the following lines:

spring-version=1.0
mysql-version=4.0.0

then it’s the same thing as if you wrote, in your pom.xml, the following lines:

<properties>
    <spring-version>1.0</spring-version>
    <mysql-version>4.0.0</mysql-version>
</properties>

Using this plugin, you will have several benefits:

  • Set easily a long list of properties
  • Modify the values of these properties without modifying the parent pom.xml.

Leave a Comment