Jenkins - Maven Configuration - maven

I need to configure my maven project that depends on local jars. For example, in Jenkins how I can configure the third party jars that cannot be downloadable from maven central repo. In my case Microsoft JDBC driver,
mvn install:install-file -Dfile=sqljdbc4.jar -Dpackaging=jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=4.0

Consider setting up a Maven repository manager like:
Nexus
Artifactory
Archiva
The build on Jenkins will then work the same way as a build on your development machine. This is how Maven was designed to work.

Related

What is the difference between deploying an artifact into Artifactory with 'mvn deploy' command and with Artifactory UI?

I usually use mvn versions:use-latest-versions command to update my dependencies to the latest ones which other teams have been deployed to our free Jfrog's Artifactory server on our local address : http://192.168.100.243:8082/artifactory/X_Douran/.
My problem is when I deploy an artifact (a jar file) with Artifactory UI or with curl (using Jfrog's Rest Api), the command mvn versions:use-latest-versions doesn't work correctly and do not update my pom but when I run mvn clean deploy on my source code of my dependent project then running mvn versions:use-latest-versions on my final project it works correctly and do update my dependency in my pom.
So I want to know what is the different between deploying via Artifactory UI and deploying via mvn clean deploy ?
You always need to deploy the POM along the JAR, otherwise Maven will not work correctly with these dependencies. Furthermore, you need to make sure that the metadata files are updated. I am not sure that Artifactory does this if you deploy using curl or the UI.
Deploying your own JARs regularly through the UI is not recommended. You should build them on a build server (like Jenkins) and then automatically deploy them to Artifactory.
Changing JAR files "by hand" should be forbidden.

How to configure maven to copy dependencies from central repo to local repository mirror (not local repo)

All
Need to get maven to copy central dependencies to local filesystem repository mirror. Can't work out how to do this in maven (3.3.1).
We have:
[1] maven central, which for the UK is: "http://uk.maven.org/maven2"
[2] local remote filesystem repository mirror: "c:/mylocalRepository"
[3] local repo "c:/users/myuser/.m2/repository"
Version of maven is 3.3.1 (doing a migration from 2.0.10).
We need to run our system without connecting to central (behind firewalls) and also without using a repository manager (Nexus, Archiva or the like) - it's something we would like to change but cannot change our infrastructure immediately. Please don't reply just saying do this.
Therefore we need our dependencies in a local file system that maven will then be use as a mirror of central.
I can't find a way to configure maven to build this - I'm getting dependencies - jar + pom and then using
To install jars:
mvn org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy-file
-Durl="file:///{repositoryPath}"
-DrepositoryId="InternalRepo"
-Dfile="{jarFile}"
-DpomFile="{pomFile}"
-DrepositoryLayout=default
-DgroupId={groupId}
-DartifactId={artifactId}
-Dversion={version}
-Dpackaging=jar
-s "C:/apache-maven-3.3.1/conf/settings_centralRepo.xml"
To install Poms:
mvn org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy-file
-Durl="file:///{repositoryPath}"
-DrepositoryId="InternalRepo"
-Dfile="{pomFile}"
-DpomFile="{pomFile}"
-DrepositoryLayout=default
-DgroupId={groupId}
-DartifactId={artifactId}
-Dversion={version}
-Dpackaging=pom
-s "C:/apache-maven-3.3.1/conf/settings_centralRepo.xml"
Ideally would like a configuration that we could put in the parent pom that would trigger all dependencies to be copied over. However the documentation implies this is for build artifacts rather than dependencies. There's usually a way in maven, but it can be hard to find.
Any help much appreciated - I've currently jury-rigged a script to do this and it tedious and labour intensive.

maven automatically deploy artifacts on Archiva?

Maybe the question is asked for more than hundred times, but I didn't find it with the search function.
Ok we've a CI Server running Jenkins and Archiva. Building our code with maven. But now our IT Department changed the proxy configuration for the CI Server. It isn't able to go online.
When I use a new artifact and build it locally, mvn downloads this and stores it in the local repo.
But when I commit the sourcecode in the SVN Jenkins fails, caused of the missing internet connection.
So is there a way to automatic deploy artifacts and maven-plugins to Archiva when I build my projects local with maven?
use mvn clean deploy that will deploy to Archiva.
You have to configure correctly distributionManagement section in your pom.
See http://archiva.apache.org/docs/1.4-M4/userguide/deploy.html
I created a Jenkins job that will execute a shell script to ask Maven to deploy our private artifact in Archiva
Prerequisites
In your .m2/settings.xml file add your server, i.e.
<server>
<id>archiva.release</id>
<username>admin</username>
<password>123456</password>
</server>
Deploy 3rd party artifacts to archiva repository shell script
#!/bin/bash
rm_host=localhost # archiva server address
rm_port=8080 # archiva port
major_version=1 #
minor_version=0 #
version_build=1 #
repository=private # your repository id in archiva
mvn deploy:deploy-file
-Dfile=myApp.jar
-DgroupId=com.company
-DartifactId=myApp
-Dversion=${major_version}.${minor_version}.${version_build}
-Dpackaging=jar
-Durl=http://${rm_host}:${rm_port}/repository/${repository}/ -DrepositoryId=archiva.release

How can I use maven project hosted at Google code as dependency?

I want to create a maven project to depend on maven-structured Google Code project that has been frozen before they has been published to maven central repo.
Since their code is available ( http://code.google.com/p/google-voice-java/source/browse/branches/maven/pom.xml ), it has properly designed pom.xml that shows all their dependencies, I believe it would be a way to specify the path to their repo, and download their code and build their artifacts as a part of my building cycle. Alternatively, I should download their jars, add to my local repo and add their dependencies to my dependencies list.
I googled much about it, but the only founding is wagon plugin, that makes opposite, it puts the build artifacts to google code repo turning it into a maven repo.
Please, advice!
This project appears to be neither published to maven central nor google code's snapshot repo
(https://code.google.com/p/google-maven-repository/wiki/ProjectSetup).
I would recommend either using:
mvn install:install-file -Dfile=… -DpomFile=… -Dpackaging=jar
or
mvn install:install-file -Dfile=... -DgroupId=... -DartifactId=... -Dversion=1.0-SNAPSHOT -Dpackaging=jar -DgeneratePom=true
This puts the artifact in your local repo directory (.../.m2/repository/) and makes it available for use in the dependencies section of your pom.xml.

Maven - Install an artifact to the Nexus repository

I have a problem currently when i run the command mvn install, the artifact is installed in my local repository (i.e. in %HOME/.m2 folder) but not in the Nexus repository.
I know with Nexus i can add an artifact manually using the GUI but is there a way to do install the artifact as part of the mvn command?
What you're seeing is normal behavior in the standard maven lifecycle. The install phase is only supposed to install the artifact locally. You need to run deploy, which comes after install. That's when maven uploads artifacts to a remote repository. The remote repo for deployment is configured in the distribution management section of the pom.

Resources