Can Jenkins be used to store project jar at some remote location after build - maven

For my project I need to store jar after each build at some other url. Is there a way to get it done by Jenkins job.
I am quite new to jenkins.

You can find a good explanation on how to publish your artifact to a repository (best practice) here. This is equivalent for Maven3 and Maven2.
The answer refers to Artifactory. Make sure to also take a look at Nexus and Archiva as khmarbaise noted.
tl;dr
If using Artifactory, add the Maven Artifactory Plugin to your pom.

Related

Is it possible to configure a Jenkins Build Job to pick maven artifacts from local maven repository

Is it possible in someway to configure my build job such that rather than picking maven artifacts from the central repo , it picks them from the local maven repo. residing on my system?
NOTE - I want others to be able to run build jobs via jenkins , while pointing to my fusion repo.
Thanks
If you want to share a maven repository with multiple users I recommend to use a repository manager see maven repository management. The mostly used once are Artifactory and Nexus. This can handle the central repo as well as own managed repositories by ThirdParties or by your self. They also work as proxy to reduce the bandwidth used in your organisation.
Much easier method to achieve local-only maven builds.
Just use the offline flag (-o):
mvn -o clean package
Maven will build off your local repo directly and will not pull down updates.

How to update maven repository manually from the maven build?

We do not have our own repository at the moment. So, when we build with maven it creates .m2 repository in the home directory of the current user.
Now there are two third party jars which are not found in the Maven Central. Suppose one of them is hasp-srm-api.jar. Today the process is this:
a. The pom.xml of the project depending on hasp-srm-api.jar contain these lines:
<dependency>
<groupId>com.safenet</groupId>
<artifactId>hasp</artifactId>
<version>1</version>
</dependency>
b. Before doing the first build we execute the following command:
mvn install:install-file -Dfile=hasp-srm-api.jar -DgroupId=com.safenet -DartifactId=hasp -Dversion=1 -Dpackaging=jar
My question is this - is it possible to automate this step? I would like to be able to tell maven to check whether the hasp artifact exists and if not - install it manually using the aforementioned command line. How can I do it?
NO. It is not possible to have maven automatically deploy an artifact into a repository in the fashion you suggest. This goes for both local and remote repositories. If the artifact exists in a some repository somewhere, you can add that repository to your build's list of known remote repos, but other than that you have to add it yourself.
You can add it to your local .m2 repository, but that will then only be good for that individual environment. Other dev's will have to repeat the process. This is one of the main attractions of running your own repository server( like Nexus ); you can add the artifact to that repository and then everyone in your organization can use it forever. There is still no way to automate the deployment of the artifact, but it's easy to do and is permanent.
Note, setting up a repository manager is very easy to do. It's highly recommended. It makes the whole Maven thing make a whole lot more sense.
The best solution for such problems is using a repository manager which results in installing such kind of dependencies only once into the repository manager and the whole company can use it a usual dependency. That's it.
Other option you have is to write your own maven plugin. May be below link will be right place for you start
MOJO FAQ

maven repositories

I'm new to maven. I'm still failing to grasp the concept of it.
For example I'm looking for com.extjs:gxt:jar:2.2.5 or org.syslog4j:syslog4j:jar:0.9.46. I can't find them in any repo. Yet they seem fairly common packages.
Does that mean I have to download them by hand ? Doesn't it defeat the whole idea of maven ?
Where can I find a good repository that will have all these artifacts so that I don't need to download the jars by hand ?
What am I doing wrong when using maven, this definitely does not seem the way to go...
You're not doing anything wrong. The issue is that those artifacts don't exist in maven central repository. By default, that's the only repository maven will download from. You can add additional repositories (see maven docs) to configure repositories that aren't mirrored to central automatically.
As #Michael said, you are not doing anything wrong.
The default Maven central repository is not going to provide every possible artifact on the earth.
Normally you can have two way to solve it:
1) The artifact you use may be provided by some organization, which they provide their own repository to host those artifact. Tell Maven to lookup those repositories so that Maven can retrieve the corresponding artifact.
or
2) Get the JAR etc and put in your local environment.
There are two most commonly used ways for the above work:
A) Have a "local" maven repository/proxy (e.g. Nexus, Artifactory), and make your Maven points to this repository. Adding new remote repository (1) is mostly done by adding extra repo to proxy under your local Maven repo. Manually handling 3rd party artifact (2) is done by deploying the JAR to your local repo.
B) All done locally by your local Maven. Adding new remote repo (1) is done by updating the settings.xml (or your project POM.xml). Manually handling 3rd party artifact (2) is done by installing 3rd party JAR to local repository.
you can use
<dependency>
<groupId>com.extjs</groupId>
<artifactId>gxt</artifactId>
<version>2.3.0-gwt22</version>
</dependency>

How to deploy JAR to Maven remote repository

Is there any way to put my JAR file in remote repository, so my maven project can get this JAR file from any place via Internet?
I have downloaded and did some fixes in the ReportNG project: https://github.com/dwdyer/reportng .
Using ANT I have compiled this project into JAR, now I want to put it into remote Maven repository, but don't know how I can do that.
Could somebody please suggest me the way, how I can perform that?
If it is a released version you want to make available in maven central follow this guide: http://maven.apache.org/guides/mini/guide-central-repository-upload.html
I'm no github professional but since a maven repo is just a file structure with some meta-data you can put it anywhere maven can read it (ftp, http, ...). so you could create a git repo to host your maven artifacts. see http://cemerick.com/2010/08/24/hosting-maven-repos-on-github/ for an example. (it may be outdated - github may have something like maven repo hosting, I just dont know)
A lightweight way to create your own maven repository is to store it on github. See Hosting a Maven repository on github for more details
I followed sonatype open source project maven deployment guide https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide and successfully deployed the latest version of reportNG into maven central repository. Now maven have both 1.1.3 and 1.1.4
http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.uncommons%22%20AND%20a%3A%22reportng%22
You should do a pull request to the github project. If the maintainer likes your fix he will put it in the next version.
If you need your fix in a remote repo NOW then you'll have to setup your own maven repository.

Configure Maven or Nexus to link trunk artifact at static URL

My current Jenkins deployment job retrieves war file generated from maven build process from Nexus repository. The deployment is done this way since I can not use hot deployment for my environments. Currently I used parameterized build with Jenkins so I can manually enter the version number for my artifact. Is there a way to configure Maven or Nexus so the artifact generate from the latest trunk build can be accessed from an static URL? For example:
http://mynexus:8081/nexus/content/repository/snapshots/com/somepackage/my-app/trunk/my-app-trunk.war
I don't know a way to do this in Nexus. But you can access the latest successful build from Jenkins, with a URL like this: http://localhost:8080/jenkins/job/jobname/lastSuccessfulBuild/my-app-trunk.war
You have to enable artifact archiving for your war file, then you can access it.
Same issue here, we discovered about :
https://wiki.jenkins-ci.org/display/JENKINS/Maven+Deployment+Linker
Which does the job.
Hope that helps.

Resources