I am using Maven 3.0, and my .m2
folder location is C:\Users\me\.m2
.
However, I do not have write access to that folder, but I want to change the repository location from the one defined in the settings.xml
.
Due to restricted access, I am not able to edit the settings.xml
to change the repository location.
How can I override the values of my settings.xml
-or change the default location of the .m2
folder- without editing my C:\Users\me\.m2\conf\settings.xml
file?
The answer above is correct. You can use the "-Dmaven.
If you want to create a folder with a . prefix on Windows, you can simply do this on the command line. At the command prompt type md c:\Users\Jonathan\. m2 (or equivalent for your ${user.
You need to add this line into your settings.xml
(or uncomment if it's already there).
<localRepository>C:\Users\me\.m2\repo</localRepository>
Also it's possible to run your commands with mvn clean install -gs C:\Users\me\.m2\settings.xml
- this parameter will force maven to use different settings.xml
then the default one (which is in $HOME/.m2/settings.xml
)
It's funny how other answers ignore the fact that you can't write to that file...
There are a few workarounds that come to my mind which could help use an arbitrary C:\redirected\settings.xml
and use the mvn
command as usual happily ever after.
mvn
aliasIn a Unix shell (or on Cygwin) you can create
alias mvn='mvn --global-settings "C:\redirected\settings.xml"'
so when you're calling mvn blah blah
from anywhere the config is "automatically" picked up.
See How to create alias in cmd
? if you want this, but don't have a Unix shell.
mvn
wrapperConfigure your environment so that mvn
is resolved to a wrapper script when typed in the command line:
MVN_HOME/bin
or M2_HOME/bin
from your PATH
so mvn
is not resolved any more.PATH
(or use an existing one)In that folder create an mvn.bat
file with contents:
call C:\your\path\to\maven\bin\mvn.bat --global-settings "C:\redirected\settings.xml" %*
Note: if you want some projects to behave differently you can just create mvn.bat
in the same folder as pom.xml
so when you run plain mvn
it resolves to the local one.
Use where mvn
at any time to check how it is resolved, the first one will be run when you type mvn
.
mvn.bat
hackIf you have write access to C:\your\path\to\maven\bin\mvn.bat
, edit the file and add set MAVEN_CMD_LINE_ARG
to the :runm2
part:
@REM Start MAVEN2 :runm2 set MAVEN_CMD_LINE_ARGS=--global-settings "C:\redirected\settings.xml" %MAVEN_CMD_LINE_ARGS% set CLASSWORLDS_LAUNCHER=...
mvn.sh
hackFor completeness, you can change the C:\your\path\to\maven\bin\mvn
shell script too by changing the exec "$JAVACMD"
command's
${CLASSWORLDS_LAUNCHER} "$@"
part to
${CLASSWORLDS_LAUNCHER} --global-settings "C:\redirected\settings.xml" "$@"
As a person in IT it's funny that you don't have access to your own home folder, for me this constitutes as incompetence from the company you're working for: this is equivalent of hiring someone to do software development, but not providing even the possibility to use anything other than notepad.exe or Microsoft Word to edit the source files. I'd suggest to contact your help desk or administrator and request write access at least to that particular file so that you can change the path of the local repository.
Disclaimer: None of these are tested for this particular use case, but I successfully used all of them previously for various other software.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With