Different Property Sets in Maven


Don't separating custom properties from code have side effects. You will have to customize a properties file according a current purpose, without loosing other property constellations for a specific build (e.g. builds for testing, builds for demo servers, etc.). These may also contain sensible customer related infos like passwords.

Keeping all those parameter files separate from code is a good idea but results in a backup-old/copy-new/renaming-new scenario. This is not convenient for a lazy developer and even my end in a not intended SVN commit of such files.

Best way IMHO is to separate property files containing changing (developer setup URLs) and sensible information (passwords) from the project's working copy itself. Using Maven you can do this with a little configuration trick. See next section how it works out.

Best Practice

For run-time configuration mechanisms, see also BestPracticeUserHomeDirConfig.


Use two different profiles one containing a default set of example properties and another one using an external filter file. The file has the syntax build-${env}.properties and has to lay in the ${user.home} directory. The ${env} property can be set to arbitrary values ( dev per default).

Pom.xml Content

               TO SEPARATE CONFIGURATION FROM PROJECT, COPY build-example.properties to 
               CUSTOMIZE PROPERTIES AND TRIGGER MAVEN BUILD WITH `mvn install -Denv=dev'.
            <!-- externalize build parameters for productive environment -->

Commandline Call

We have three possibilities to build the project:
Example Parameters
mvn install (uses properties from default profile)
Custom Parameters
mvn install -Penv-dev (uses a filter file laying at ${user.home}/sps-build-dev.properties)
Arbitrary Parameters
mvn install -Penv-dev -Denv=other_custom_demo_server_deploy_config (uses a filter file laying at ${user.home}/sps-build-other_custom_demo_server_deploy_config.properties)


Change your local.configfile pattern to refer to the project you are about to work with (e.g. sps_v2-build-${env}.properties). Then you can have all the build files laying together in your system.

Topic revision: r6 - 23 Sep 2014 12:16:14, EikeJuerrens
This site is powered by FoswikiCopyright &© by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Wiki? Send feedback