Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Jenkins Maven Release: Replace Snapshot Dependencies

In one of our maven projects, we have a dependency to a Commons-POM, which is also used by other projects and therefore not part of the Parent-POM. Since it is also under development we refer to the SNAPSHOT version.

When creating a release with Jenkins, it will use the snapshot dependency. But what we want is to use the latest release or simply replace the snapshot with the release version.

So is it possible in Jenkins to replace the snapshot versions? Maybe the same way, Maven Release plugin does it when performing manually (it prompts for resolving the dependencies)?

like image 805
fischermatte Avatar asked Mar 22 '23 21:03


2 Answers

The Versions Maven Plugin offers the goal versions:use-latest-releases. You can use this goal in a pre-step maven call prior to your your regular build like this:

versions:use-latest-releases -Dincludes=com.yourcompany.yourgroupid:yourartifactid versions:commit scm:checkin

That way, you can keep the SNAPSHOT dependency until the artifact is actually released.

like image 98
Andreas Hacker Avatar answered Apr 24 '23 11:04

Andreas Hacker

Maybe it's possible with not hardcoding the version but having a parameter (<version>${dependency.version}</version>) and then starting the build with mvn clean install -Ddependecy.version=VERSION (in Jenkins you can parametrize builds). But this is nothing more than a hack!

Having SNAPSHOT dependencies during development is ok (and sometimes a pain ;-) but before releasing your project you should release the dependency.

If the development of the commons project is (currently) tightly coupled to your project you could consider having the commons project in the same release cycle like your project for the time being.

like image 45
rotscher Avatar answered Apr 24 '23 11:04