Using Maven for multiple deployment environment (production/development)

FYI best practice is to not have to rebuild your artifact for different environments – as that does not lead to re-produce-able builds, and other things could potentially change when rebuilding. I.e. using resource-filtering, as suggested above, only works when re-building your project.

When you graduate an artifact from dev to test or acceptance test to production – you do not want to have to rebuild.

What you want to do, is actually have your configuration dynamic, dependent on run-time variables. I.e. different spring setups or properties files for different environments e.g:

db-dev.properties
db-test.properties
db-prod.properties

Then you can switch between these configurations using run-time variables and Spring’s PropertyPlaceholderConfigurer.

You can also actually use different spring configuration files as well, as I’ve done in the past, for more complex setups.

I also suggest you leave your ‘default’ setup as production – so that if you deploy to production, you don’t need to worry if you forget to set the environment variable.

Leave a Comment