How Jenkins Maven deploy Plugin works - java

I have a java project I'm working on, and so far I've used mvn deploy to upload artifacts to nexus. As far as I can tell, Maven looks at the distributionManagement element in the POM and, if the current version is a snapshot, it uploads to the repository configured as snapshot, otherwise it uploads to the release repository. For this to work, both need to be configured in the POM.
What I'd like to know is if this behavior is the same with Jenkins Maven Integration Plugin. Do I need to set both repositories within the POM? If not, how can it know when to upload to snapshot repo and when to release repo (since it only asks for 1 URL or ID)?

It should be the same with Jenkins Maven integration plugin.
You are suposed to specify same things at pom.xml

Related

Phases/Plugins and Maven Project Builder

When i save changes in my java source code with Eclipse i notice in the Progress tab
As i am using Maven which phase or plugin (goal) is being invoked here ?
What happens behind the scene ?
simply it updates maven dependencies based on your pom.xml or resolves Maven dependencies from the Eclipse workspace without installing to the local Maven repository.
visit this site to know about that in detail https://maven.apache.org/ref/3.0.1/maven-core/apidocs/org/apache/maven/project/ProjectBuilder.html
Any change to the source code or pom file of the project signal eclipse to rebuild (if build automatically is enabled). However, maven builds, would check for the required artefacts from the remote repository and download them to local repository (under .maven dir) before running compile phase. Maven plugin can be configured to run offline in which when remote repository will not be queried - making the build execute faster.

Apache Archiva Maven releated

I am trying to use Apache Archiva as my project repository. I configure archiva and am able to upload the snapshot to archiva using mvn deploy since i configured the details in pom.xml and settings.xml respectively.
Now i have snapshots which are under development, and at the time of release, i would like to move the latest artifacts from snapshots to internal(release). May I know the configuration details? I tried with maven release:prepare but it is failing since i have to mention SCM also in that. In this case, it is just about moving artifact from snapshot to internal, a different compilation is not required.
Please help on this.
I was able to achieve this using release:perform by mentioned scm pointing to git repository. release:prepare took the checkout and pushed a release as well as created a tag in git.
Thanks

How to add java library without no repository to pom file?

I'd like to add one project A as my dependency, but unfortunately, there's no repository host this library. I know that I can install it to local repository manually, then refer this in pom file. But I have a travis build job where there's no such artifact, is there any way that I can install this library to local repo automatically ? Thanks
I would recommend to use the clean approach and uploading this library into your own repository. If you don't have one: time to get one running.
If you're really not up to this task the maven install plugin: http://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.html can install a jar in the local repository. This will work both locally and on a CI server.
To upload a jar in a remote repository there is the deploy plugin: http://maven.apache.org/plugins/maven-deploy-plugin/deploy-file-mojo.html
If you bind the execution of this plugin to a very early phase in the maven life-cycle (validate) you might be able to avoid a build step required prior of your own build.

Recompiling third party Java code in a restricted environment

I have user-level access to Jenkins and cannot change the settings.xml for Maven due to access restrictions. When I want to mvn deploy, it expects to have a distributionManagement clause in the pom.xml. The code however comes from the internet and I rather don't change the pom.xml every time. Is there something I can do in Jenkins? I am considering using the Artifactory plugin because that is where I want to deploy.
I'd recommend using mvn deploy from Jenkins, but specifying the repository to deploy to with the -DaltDeploymentRepository=id::layout::url system property.
Format: id::layout::url
id is the repository id to be used to get credentials from the settings.xml (i.e. central, snapshot)
layout should be "default", unless you are still using Maven1 (in which case it should be "legacy")
url is the URL for the repository you want to deploy to.
This is specified in the Maven documentation here: https://maven.apache.org/plugins/maven-deploy-plugin/deploy-mojo.html
The Artifactory plugin seems a good solution if you cannot use the Maven deploy goal.
With a simple mvn clean install command + the Artifactory plugin, you will be able to deploy where you want (if the Jenkins server has the relevant read/write access):

Travis CI not using extra Maven repository provided in pom.xml

I have a Java-based GitHub project, fitnessjiffy-spring (I'm currently focused on the "bootstrap" branch). It depends on a library built from another GitHib project, fitnessjiff-etl. I am trying to configure both of these to be built by Travis CI.
Unfortunately, Travis is not as sophisticated as Jenkins or Hudson in dealing with Maven-based Java projects. Jenkins can easily handle dependencies between projects, but the same concept doesn't seem to exist with Travis. If one project depends on another, then that other project must already be built previously... and its artifact uploaded to some Maven repo where the first project can download it later.
My "fitnessjiffy-etl" library is building and deploying just fine. I'm using Bintray for Maven repository hosting, and you can clearly see my artifacts over plain HTTP at:
http://dl.bintray.com/steve-perkins/maven/
In my "fitnessjiffy-spring" project, I am adding this Maven repo location directly in the pom.xml, so that Travis will be able to find that artifact dependency. Here is the state of my POM at the time of this writing. Note the <repositories> element at the bottom of the file.
When I build this project locally, it works just fine. I can see it downloading the Maven artifact from "http://dl.bintray.com/...". However, when I try to build on Travis CI it fails every time. I can see in the console log that Travis is still trying to download the artifact from Maven Central rather than my specified repo.
Does this make sense to anyone else? Why does Maven utilize a custom repository location in a POM file when building locally, but ignores this configuration when running on a Travis CI build?
From digging into this further, I discovered that Travis uses its own proxy for Maven Central, and has configured Maven to force ALL dependency requests through their proxy. In other words, it does not seem possible at this time to use additional Maven repos specified in the POM file of a project built on Travis.
In my case, I ended up refactoring such that project would not need the outside JAR dependency. I also switched to Drone.io, so I could manage my settings on the build server rather than having to carry a YAML file in my repository (which always struck me as a bit daft).
However, even on Drone it's still a major hassle to manage dependencies between multiple projects (extremely common with Java development). For Java, I just don't think there's currently an adequate substitute for Jenkins or Hudson, maybe running on a cheap Digital Ocean droplet or some other VPS provider instance.
In your install phase add a $HOME/.m2/settings.xml define your custom repository.
cache:
directories:
- "$HOME/.m2"
install:
- curl -o $HOME/.m2/settings.xml
https://raw.githubusercontent.com/trajano/trajano/master/src/site/resources/settings.xml
- mvn dependency:go-offline
script:
- mvn clean install site

Categories

Resources