I thought I’d throw this out there for anyone that might find this convenient:

As Maven users know, local maven settings reside in $HOME/.m2/settings.xml

However, sometimes I use some settings/config for when I’m working on open source projects that assume Maven central + Sonatype signature defaults, and I use different ones when working on work (closed source) projects that assume our company Artifactory server and other permissions.

Ordinarily you’d modify the settings.xml file every time you wanted to switch settings – comment out one profile, enable another, comment out (or uncomment) the <mirror> setting, whatever.  This is a big pain for me during the day when I switch back and forth, so I wrote a bash script that allows me to easily switch between configs using symbolic links:

https://gist.github.com/lhazlewood/0ffbbb6d3d043c147710

To use this you would need to:

  1. Download the above script and make it executable:
    chmod u+x m2
    
  2. Ensure this script lives in a location in your $PATH.$HOME/bin and that dir is in my $PATH.

  3. In your $HOME/.m2 directory, set up one or more maven settings.xml files, with the following naming convention:

    name1.settings.xml
    name2.settings.xml
    ...
    nameN.settings.xml
    

    where nameN is the name of the environment you wish to reflect.

    For example, in my $HOME/.m2 directory, I currently have 2 files:

    opensource.settings.xml
    work.settings.xml
    
  4. Create a symbolic link named settings.xml that points to the one you want to be in effect:
    cd $HOME/.m2
    ln -s work.settings.xml settings.xml
    

After this setup is done and the executable m2 file is in your path, you can do the following:

  1. See which maven settings are in effect:
    m2
    
  2. Change your settings.xml to point to opensource.settings.xml:
    m2 opensource
    
  3. Change settings.xml to point to work.settings.xml:
    m2 work