How to generate maven artifact with jenkins build number - maven

I'm trying associate maven artifacts name with build number.
ex: sample.1.0.0-snapshot.ear into sample.1.0.0-snapshot.buildnumber.ear
I have tried maven-buildnumber plugin but still no luck.
could anyone help me to do this.

You can use the Versions Maven plugin by executing following command before any other maven targets after clean.
mvn versions:set -DnewVersion=sample.1.0.0-snapshot.$BUILD_NUMBER

Related

What is the supported way to change version on deploy for Artifactory Maven Jenkins plugin

I'm using the Maven jfrog plugin: https://jenkins.io/doc/pipeline/steps/artifactory/#rtmavendeployer-set-maven-deployer
I want to change the version of the artifact on deploy so it has the feature branch name in it.
I tried to run the set version goal. It succeeds but just totally ignores the version
rtMavenRun (
pom: "pom.xml",
goals: 'versions:set -DnewVersion=1.2.3-SNAPSHOT clean install',
resolverId: 'resolver-unique-id',
deployerId: 'deployer-unique-id'
)
The problem is the following: You call the goal versions:set and the phases clean and install in one Maven run. Before the first goal runs, Maven has already resolved the version for all goals/phases that are run. Therefore, you change the version in the POM, but as Maven has already read it, you will not be able to see it during this run.
What are possible solutions?
You can run versions:set first and then clean install in a separate Maven run.
You can use the property ${revision} in the definition of <version> and then set this property on the command line.

Maven plugin removed is still usable

I added to my maven project the a PMD and checkstyle plugins. And when I run them the work perfectly. But when I remove them from the pom.xml I can still run mvn checkstyle:checkstyle or mvn pmd:pmd even though I removed them. Also after removing them I ran mvn clean install. ANy idea of what could happen ?
The commands you execute are plugin goals (plugin:goal) and unlike "mvn install" not a phase.
you can run almost any plugin on a project if maven can find it. The apache maven plugins allow that shortcut notation (pmd:pmd) since maven will try to resolve them in the apache namespace.
Plugins from other sources would need to be run with their full name, for example:
org.codehaus.mojo:versions-maven-plugin:2.5:display-dependency-updates
The plugin itself decides if it can run a goal on its own or if it requires a running reactor and only works within the maven life-cycle (usually because it depends on outputs from other phases)
So in your case: mvn install should not run the pmd plugin anymore if its not in the pom - and install is a phase. mvn pmd:pmd will run it directly with its default config - since pmd:pmd is a plugin goal.
The default plugins per packaging and phase are documented here. These may run if in the pom or not (depending on whats in the project).

running maven sonar from unix

I have a mvn project. I want to run it against sonar.
e.g. the following command - mvn org.codehaus.mojo:sonar-maven-plugin:2.0:sonar
Without going in and modifying the application pom file to add sonar plugin, is there another way that I can call the mvn command and reference sonar plugin ?
I don't know how it works, but if you execute it from Jenkins with the Sonar plugin it will work without modifying your pom.xml.

Getting Artifactory Plugin to work with Jenkins and Maven

I have a large Maven project in Jenkins. It consists of a parent project, and about a dozen local projects. Using Jenkins, I am able to do mvndeploy` and for the build to successfully deploy to my Artifactory repository.
However, I can't seem to get the Jenkin's Artifactory plugin to work itself to work.
My Artifactory setting in Jenkins:
And here's the setting for our job:
When using the Jenkins Artifactory Plugin you should execute mvn install instead of mvn deploy.
This is because the plugin collects the published artifacts from Maven and when executing mvn deploy directly you are kind of by-passing it's behavior.
Use Build Step "Invoke Artifactory Maven 3" when working with Artifactory plugin. And most preferably use goals "clean install"
I had the same problem and resolved by adding details under Build Environment -> Generic-Artifactory Integration as shown in below image
Published Artifacts now started uploading into desired location in artifactory.

Maven: Command line to download the dependencies described in the pom.xml

I would like to know the maven command line to download the dependencies described in the pom.xml.
It is that : mvn dependency:copy-dependencies ?
Try the dependency:go-offline goal. It's meant to be used to resolve dependencies to the local repo before using the -o switch to go to offline mode. But the goal itself has no bearing on going offline. The name may be misleading.
Goal that resolves all project dependencies, including plugins and reports and their dependencies.
Here's the details about the dependency:copy-dependencies in case you're interested
Anther option is the dependency:resolve goal
Goal that resolves the project dependencies from the repository.

Resources