Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

per-user Maven properties

Tags:

java

maven-2

In my Maven build I would like to be able to define default values (e.g. for database connection) in pom.xml, but I would like the user to be able to override these without having to modify pom.xml directly.

By way of example, in an Ant build you can define default properties in foo.properties, but Ant will look for overrides for each of these in a foo.$USERNAME.properties. The latter is generally not checked into source control, which eliminates the problem of developers accidentally committing their overrides of the default properties. Does Maven offer a similar facility?

To make the problem a bit more concrete, assume I have the following defined in pom.xml

<properties>
  <db.url>jdbc:jtds:sqlserver://10.10.10.10:1433/somedb</db.url>
  <db.driver>net.sourceforge.jtds.jdbc.Driver</db.driver>
  <db.username>default_user</db.username>
  <db.password>secret</db.password>
</properties>

Can a user override these properties without editing the pom.xml directly?

like image 871
Dónal Avatar asked Jun 22 '11 09:06

Dónal


1 Answers

You can specify properties on the command line using -Dpropertyname=value, or the user can specify properties in their .m2/settings.xml.

like image 120
artbristol Avatar answered Oct 14 '22 07:10

artbristol