Jenkins Maven job doesn't use localRepository from settings.xml - maven

I have three Jenkins Maven jobs: one that builds and installs dependencies (JARs) and two that use those dependencies to bundle deployable WAR files.
I have configured all the three jobs to use a specific settings.xml file and, while not fully understanding the difference between the Settings file and Global Settings file (even after reading the ?, it's not clear), under Build I set both fields to the file path I wish to use, just in case:
/opt/maven/conf/settings.xml specifies:
<localRepository>/var/lib/maven/repo</localRepository>
however, the dependencies get downloaded in a different location: /var/lib/jenkins/maven-repositories/1 as /var/lib/jenkins is JENKINS_HOME.
The console output logs the following:
Executing Maven: -B -f /var/lib/code/src/pom.xml -Dmaven.repo.local=/var/lib/jenkins/maven-repositories/2 -s /opt/maven/conf/settings.xml -gs /opt/maven/conf/settings.xml clean install -P depBuild
which is confusing because maven.repo.local is different that what the file listed under -s and -gs says it should be.
Why does it not download and install dependencies in the local repo I specify in the settings.xml I tell it to use?
Here is the whole settings.xml:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>/var/lib/maven/repo</localRepository>
<servers>
<server>
<id>build.tomcat.all</id>
<username>buildman</username>
<password>mypass</password>
</server>
</servers>
<pluginGroups></pluginGroups>
<proxies></proxies>
<mirrors></mirrors>
<profiles></profiles>
</settings>

Try configuring it using the Config File Provider Plugin. After installing this plugin, you can create a config file in Manage Jenkins > Managed files > Add a new Config > Maven settings.xml.
It also starts you off with a template so you can just modify what you need. I just added the <localRepository> tag after the commented explanation about it.
Then in your Maven job, choose "provided settings.xml" and select the config file you just created.
Make sure you don't have any overriding options in MAVEN_OPTS and that "Use private Maven repository" is not checked.
PS: It doesn't look like you need to do this with "Global settings.xml" - you can leave that as "Use default". My limited understanding is that the global settings affects all users of the maven system, while the non-global one only affects the user that runs maven. I don't think it matters for most projects, but maybe if you have a special project where some shell execution happens under a different user, this could be important. (I'm just guessing.)

Related

how to deploy artifacts (jar files) from POM.xml into jFrog repository?

I am new to this repository world.
I have a maven project i.e MavenExample from GitHub. and I have installed a jFrog artifactory in my machine.
My Aim is to deploy all the jar files listed in my pom.xml into jFrog artifactory instead of .m2 repo (default). This deployment of jar file must ocucur after mvn deploy command.
I have tried adding distributionManagement inside Pom.xml and changing the settings.xml inside maven/conf.
Can someone help... much appreciated.
Edited:
You can try editing "localRepository" in your settings.xml":
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
<!--
REST OF THE CODE
-->
</settings>
Go to your project directory and launch "mvn deploy".
The easiest way to obtain this information is from the "Set Me Up" section of Artifactory. Select the repository in the Artifacts tab, and in the top right corner, click "Set Me Up". Assuming you are using a local repository for deploying (remote will not work for deploying, only for resolving dependencies), it will show a section for deploying which will include the distribution management section. Place this in the pom.xml file of the parent project and this running the mvn deploy command from this directory will deploy to Artifactory.
A great way to see a working example of this is to view the "maven-example" section in JFrog's public Github page . You can see the parent project has 3 sub-modules (multi1, multi2, and multi3). Adding the distribution management section mentioned previously to the parent pom.xml file and then running mvn deploy from the parent project's root directory will deploy all the binaries to Artifactory.
If for some reason this is still not working, please provide your pom.xml for the parent, the name, package type, and if it is a local/remote/virtual of the repository. Additionally, please provide any output of the mvn deploy command (with the -X option) and anything you can find in the artifactory.log and request.log files ($ARTIFACTORY_HOME/logs/artifactory.log and request.log)

Maven Release plugin: Doing the git push via https

On our jenkins box we clone our repo using https rather than ssh. However when I run the
mvn release:prepare
command it is pushing the commits via ssh. I am pretty sure it is because in my pom.xml in the scm section I have
<connection>scm:git:ssh:<internal package></connection>
<developerConnection>scm:git:ssh:<internal package></developerConnection>
I am pretty sure I can just change that to to be something like https: however where do I put the username and password so that it can connect?
The credentials are stored in mavens settings file, so that the are not exposed in the pom.
Add a server section to your ~/.m2/settings file with your GitHub user/password, i.e.
<servers>
<server>
<id>GitHub</id>
<username>[User]</username>
<password>[Password]</password>
</server>
</servers>
Add a property <project.scm.id>GitHub</project.scm.id> to your properties section in the pom.
The reference to the server Id is not detailed in the release plugin config but the top level pom properties.

How to move maven directory ".m2" from my home directory after installing IntelliJ

I've just installed IntelliJ 15 on Ubuntu and wanted to update maven repository indices, I am having disk space errors because my home folder is on a limited size partition.
I am totally lost trying to move ~/.m2 to somewhere else. I've tried IntelliJ settings and changed paths and maven settings but didn't work and most of the time they return to the home folder after restarting IntelliJ.
I wanted to add that I didn't install maven (using apt-get install maven). Would this help or give more control?
You can modify the location of the Maven local repository by modifying the Maven settings. From Configuring your Local Repository:
The location of your local repository can be changed in your user configuration. The default value is ${user.home}/.m2/repository/.
<settings>
...
<localRepository>/path/to/local/repo/</localRepository>
...
</settings>
Note: The local repository must be an absolute path.
Since you are using the Maven installation that is shipped with IntelliJ and not your own Maven version, you can create a Maven user settings:
Create a file settings.xml under ${user.home}/.m2/
Have the following content in it:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>/path/to/local/repo</localRepository>
</settings>
Maven will read this file and use the specified local repository.
Another alternative I found is also by eclipse itself.
Create the setting.xml file in my D:\TAAS\settings.xml directory as follows:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>D:\TAAS\.m2\repository</localRepository>
</settings>
Then I configured it by the eclipse itself according to the following figure.
This is an option for maven embedded versions.

Maven - 2.2.1 -------Access denied error

Access denied error coming while building using the maven 2.2.1 build tool
It might be about folder that contains your source code permissions or maven repo authentication.
First look at the folder permissions. If this does not solve your problem you can try to add auth information of the repo that you try to download from, into your settings file;(Settings file is settings.xml in conf folder in your maven installation folder or under .m2 file)
<settings>
<servers>
<server>
<id>myrepo</id>
<username>myusername</username>
<password>password</password>
</server>
</servers>
</settings>
You can see this part in your default maven settings file as commented. You can read comments as a simple documentation of settings file.
This happens when multiple processes are trying to access the same file simultaneously.
Most likely one process in reading this file and another is trying to write it at the same time when your IDE where its trying to compile the project while you are running maven from the command line.

unauthorized access on artifactory even though credentials are included

I am trying to deploy a zip file to a remote inhouse maven repo.(artifactory integrated into hudson).
pom.xml
...
<modelVersion>4.0.0</modelVersion>
<groupId>mygroupId</groupId>
<artifactId>myartifactid</artifactId>
<version>1.0-SNAPSHOT</version>
<distributionManagement>
<repository>
<id>hudson</id>
<name>hudson-releases</name>
<url>http://url to repo</url>
</repository>
</distributionManagement>
...
settings.xml
<servers>
<server>
<id>hudson</id>
<username>username</username>
<password>password</password>
</server>
</servers>
maven deploy
mvn deploy:deploy-file -Durl=http://url -Dfile=file-1.0.0.zip -Dpackaging=zip -DpomFile=pom.xml
maven quits with return code 401.
Looking at artifactory's logs
2011-07-15 13:52:50,090 [DENIED DEPLOY] libs-release-local:somefile.zip for anonymous/192.168.220.146.
I don't understand why maven doesn't use the supplied credentials.
What am i doing wrong here ?
Tip to solve the problem with the clear text password:
Access and login into Artifactory.
Once you are logged in, click over your user name, on the superior right corner of the screen.
Put your password then clique in the em Unlockbutton, enabling the encrypted password.
Copy the tag that will be showed on the inferior part of the screen and paste it into the settings.xml file. If you prefer to just copy the password, be sure about let it exactly equals the tag showed below, including the "\" at the beginning of the password.
Remember to adjust the tag with the id of your server, defined into the tag, in your POM.xml
Click in Update button and ready! Check if everything will occur well at the next project's publication.
DonĀ“t forget to check that what you put on <distributionManagement> at your pom.xml corresponds to what is on the tags of your .m2/settings.xml.
Hudson is most likely caching settings.xml. You can try to reload configuration from the disk using this url http://your-hudson-url:8081/hudson/reload or restart the container Hudson is running on. Worked for me.
For some reason using a POM file didn't work. So i had to do it from command line.
mvn deploy:deploy-file -Durl=http://url -Dfile=file-1.0.0.zip -Dpackaging=zip -DartifactId=aid -DgroupId=groupId -DrepositoryId=repId -Dversion=1.0-SNAPSHOT
I still do not know why this worked. Also , i didn't have to change settings.xml from what i listed before.
EDIT
Also, on the home tab in artifactory, you can get maven settings by clicking "Maven settings->Generate Settings" .
Maven is not set to use preemptive authentication by default and has some issues when being challenged.
You can try configuring Maven's HttpClient Wagon to do preemptive authentication (http://maven.apache.org/guides/mini/guide-http-settings.html), though I rarely managed to get it working properly.
Since you're using Jenkins\Hudson, you might want to take a look at the Jenkins\Hudson - Artifactory plugin:
https://wiki.jenkins-ci.org/display/JENKINS/Artifactory+Plugin
http://wiki.hudson-ci.org/display/HUDSON/Artifactory+Plugin
You're publishing a snapshot version but you haven't specified a snapshotRepository tag in the distributionManagement section of your POM. Alternatively try and deploy a normal version and see if that works
Update Maven configuration details and add the credentials of nexus:
credentials: admin

Resources