You build software for multiple companies, or perhaps just one company, but
you also have some side projects. You do all this on the same machine. Each
company has their own Maven artifact server, each with its own settings.xml
file and potentially other settings and company-specific build artifacts, all
wanting to be stored in the same ~/.m2
directory. You know you can use
Docker or Vagrant to keep things isolated, but feel they are extreme
solutions to this problem. You really just need a simple way to switch between
Maven environments.
mem
(Maven Environment Manager) is a simple command-line tool to create
and switch between Maven environments. It works by converting your ~/.m2
directory into a symbolic link which points to your current environment,
located at ~/.m2.<environment>
, e.g. .m2.foobar
for the foobar
environment.
mem
is known to work in the following environments:
- Linux distributions with bash
- macOS / OS X
- Windows Subsystem for Linux
mem
doesn't work with Git Bash as it cannot create symbolic links.
To start managing your Maven environments with mem
:
mem init
This will rename your ~/.m2
directory to ~/.m2.default
and create a
symbolic link pointing ~/.m2
to ~/.m2.default
. This effectively creates
the first environment, called default, and switches to that environment.
To create an environment and switch to it:
mem create <environment>
For example, to create a new environment called work:
mem create work
To switch to an environment:
mem use <environment>
For example, to switch to an environment called side-projects:
mem use side-projects
To list all your Maven environments:
mem
Example output:
Maven environments:
* default
* side-projects [active]
* work
To delete an environment:
mem delete <environment>
For example, to delete the environment called side-projects:
mem delete side-projects
mem
will not allow you to delete the currently active environment, because
there must always be exactly one active environment and mem
isn't smart
enough to choose the environment which should become active after the active
environment is deleted.
To delete the currently active environment, you must first switch to another environment.
mem
is a bash script with no dependencies on things like sed
and awk
,
which may not be found in all bash environments.