Wednesday, December 12, 2007

Good use of maven2 profiles

As my previous blog eluded to, I work on a project that has to support multiple databases. Having continuous integration servers is key to ensuring the quality of your software across multiple databases. We have successfully supported multiple database almost from the inception of the project. Starting with SQL Server (client mandated) and PostgreSql, we're now moving to Oracle.

Our CI environment will run tests against the multiple DBs as necessary. But how can I run integration tests against the different databases, easily, to ensure my code changes work on supported DBs?

Enter, maven profiles.

In my development environment, I have 3 profiles declared just for this project. The first is declared with 'activeByDefault' set to true. All of the generic or common settings for my project are found in this profile. Samples of the settings include my log4j file location, web application home directories (JBoss in our case), and overall maven settings (tests on/off).

The second and third profiles include information specific database information. One profile runs against SQL server and another against Oracle. Both of these profiles are activated by a specified environment variable on the maven command line.

How does this help with testing? If I have a DB instance for both SQL server & Oracle already set to go, I can simply run maven specifying my environment and have integration tests executed against the DB of my choice.

mvn -Denv=ENV1 install

vs

mvn -Denv=ENV2 install

It doesn't get much simpler than that!

1 comment:

jlorenzen said...

Just as a warning
http://jlorenzen.blogspot.com/2008/12/maven-profiles-something-you-need-to.html