This might be a weird question but this is happening to me. Can anyone tell me whice repository location does Jenkins use when we are building a Maven project? I have chosen Default (~/.m2/repository)
option while configuring Jenkins but it seems the behavior is a bit different. Though there is this myown.jar present in my local repository i.e. in /home/username/.m2
, it shows the error that myown.jar is not found. So I have to build a job for this myown
project, build it and then the error gets solved.
Not only this, when I put the Jenkins script in startup i.e. /usr/bin/java -jar <warpath>.war
, it downloaded all the dependencies of my projects again while building it, though I had built the configured project 5 times before putting the script in startup !! Isn't it weird behavior? Which repository location does Jenkins use? Or is there something what I might be missing?
m2\repository is the default Maven local repository location. You can change the user name under which the Jenkins service runs under and that will change the USERPROFILE as well. You can also see it in Jenkins > Configure Jenkins > System Information webpage.
Maven's local repository is a directory on the local machine that stores all the project artifacts. When we execute a Maven build, Maven automatically downloads all the dependency jars into the local repository. Usually, this directory is named .
There is a setting in the Jenkins job configuration to use a private repository. This way you can avoid artefacts from your Jenkins build finding their way into your main repository. You need to open the extended options for the Maven build to see the option.
actually it depends on configuration of each individual maven project. By default, Jenkins will use the local repository JENKINS_HOME_DIR/.m2/repository
if you install the maven by ticking the Install automatically checkbox, otherwise it will use the local /home/username/.m2/repository.
however you can change this default location by setting up the settings.xml file in ~/.m2/settings.xml
OR
for global use you can change it from jenkins_home_dir/conf
for example if you install maven by tick Install automatically checkbox
Step1.
Choose the maven Installation for a particular project in jenkins home directory
$ cd Jenkins_home_dir/tools/hudson.tasks.Maven_MavenInstallation/
Step 2.
change the localRepository in settings.xml
The hierarchy for settings.xml is user .m2
directory and if it could not find that, it will try to find the one in {maven home}/conf/settings.xml
.
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