wood burning stoves 2.0*
The moose likes Ant, Maven and Other Build Tools and the fly likes maven 2:  How can I avoid hard-coding my username in my pom.xml, scm configuration? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "maven 2:  How can I avoid hard-coding my username in my pom.xml, scm configuration?" Watch "maven 2:  How can I avoid hard-coding my username in my pom.xml, scm configuration?" New topic
Author

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

Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
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

Joined: Jun 25, 2001
Posts: 15951
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
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

Joined: Jun 25, 2001
Posts: 15951
    
  19

Should be about right.
Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
Thank you. To my first question, where does ${user.name} get defined? In what file (e.g. settings.xml)?

- Dave
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9924
    
158

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)


[My Blog] [JavaRanch Journal]
Dave Alvarado
Ranch Hand

Joined: Jul 02, 2008
Posts: 436
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

Joined: Jun 25, 2001
Posts: 15951
    
  19

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.
 
wood burning stoves
 
subject: maven 2: How can I avoid hard-coding my username in my pom.xml, scm configuration?
 
Similar Threads
maven subversion
Maven: No SCM URL was provided to perform the release from
install error -- The packaging for this project did not assign a file to the build artifact
[WARNING] Your scm URL use a deprecated format. The new format is :[username[:password]@]hostname:po
maven subversion