The First Cry of Atom Today is the first day of the rest of my life.

Maven Wrapper Home

Maven wrapper is a library to make maven build easy. You do not need to install maven manually thanks to maven wrapper because it automatically install the specific maven version into your project. Since I usually use gradle wrapper and sbt-extras, it was very easy to use maven wrapper as well in my Java project.

But I had a trouble to build a project after switching user. For example, I wanted to create build environment by root user but building the project itself should be done by non-priviledged user. I initially thought it can be achieved by sudo -u lewuathe:

$ sudo -u lewuathe ./mvnw install 

But it failed due to FailNotFoundException.

Exception in thread "main" /home/lewuathe/.m2/wrapper/dists/apache-maven-3.3.9-bin/2609u9g41na2l7ogackmif6fj2/ (No such file or directory)
    at Method)

I was disapponted of this because I believed maven wrapper automatically :( I read the source code of maven wrapper and finally found a solution. Maven wrapper gets the base directory where maven is installed from MAVEN_USER_HOME environment variable.

So finally what we need to do is this:

$ mkdir /home/lewuathe/.m2
$ MAVEN_USER_HOME=/home/lewuathe/.m2 sudo -u lewuathe ./mvnw ...

It worked!