Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

maven 2: How can I avoid hard-coding my username in my pom.xml, scm configuration?

 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm using Maven 2.2 on Mac 10.5.6. I am trying to use the release plugin to publish a release and have this configuration in my pom.xml file ...



Notice the username, "dalvarado" embedded in the connection string. Is there some way I can put a generic variable there and define the variable in my M2_HOME/settings.xml file?

Thanks, - Dave
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use any of the properties defined as available by the System.getProperty method plus any user-defined properties (-Dname=value) that you have on the Maven command line. I believe the one you want would be referenced as "${user.name}", but check the java.lang.System Javadocs to be sure.

On second thought, don't bother. I just did. It's user.name, like I said.
 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, but I'm still not clear in what file you found define "${user.name}" and how it would be defined (e.g. user.name=dalvarado). Also, you are saying that in my string I should write it like this ...



? Thanks , - Dave
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Should be about right.
 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. To my first question, where does ${user.name} get defined? In what file (e.g. settings.xml)?

- Dave
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Alvarado wrote:Thank you. To my first question, where does ${user.name} get defined? In what file (e.g. settings.xml)?



The user.name is one of the default Java System properties. See System.getProperties (look for user.name)
 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a more Maven specific solution? Although I'm building a Java web project, I'm hoping this has a solution in the Maven realm. I used to use Maven 1 and I could define this version control user name in build.properties but Maven 2 does not use such a file.

- Dave
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a per-user Maven properties file. It's located in the ".m2" directory right next to the repositories directory.

The System user.name property is set by the JVM that's running maven to the user's login ID. When everything's LAN-based, that's also the best ID to use for other resources like the source control system, since otherwise you end up with a rat's-nest of identities that all have to be maintained separately, and not uncommonly, you end up with people sharing accounts, leading to an inability to determine responsibility when things go wrong and the shouting starts.

Plus, of course, if you're subject to auditing, auditors absolutely hate that, for that very reason.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic