4

is it possible in Maven to configure different local repositories for SNAPSHOT and RELEASE artifacts?

The reason I am asking, we are using Jenkins for continuous build for our project. To ensure the consistency (if same artifact is built from different Jenkins jobs because of race condition, we can experience chaotic behavior) before build start, we create a fresh local repository for Jenkins.

Now the problem is, our project is huge, so for every build we have to download lots of dependencies from our Nexus but when you think about it, there is no reason to download every time new the RELEASE artifacts. The RELEASE artifacts don't change from build to build, for ex, Spring 4.5, httpclient 4.0, aspectj 1.8.1 is same for one build to another.

So actually to ensure the consistency, we only should not have the SNAPSHOT dependencies in the repository. If we could have two local repositories one for RELEASE artifacts and the other for SNAPSHOT's, then before every build start, we could delete the SNAPSHOT repository but re-use the local RELEASE repository, which would save me gigabytes of download from Nexus.

I know we can do RELEASE, SNAPSHOT configurations for remote repositories, is it possible to do same sort of configuration for local repositories?

If this is not possible, how would you solve this problem.

posthumecaver
  • 1,584
  • 4
  • 16
  • 29
  • You should use separate repositories for snapshot and release, the pom config is explained here http://stackoverflow.com/questions/14211697/how-to-configure-maven-project-to-deploy-both-snapshot-and-releases-to-nexus – Essex Boy Jan 12 '17 at 10:18
  • What in this article explained is remote repositories (it is discussed over deploying to Nexus). This is not what I want, I want to define two local repositories, one for SNAPSHOT, one for releases. This is how it configured in settings.xml "c:\repo". I like to have something like "c:\repo_snap" and "c:\repo_rel" or a way to produce similar effect. – posthumecaver Jan 12 '17 at 10:36
  • sorry I misunderstood I have added an answer, you should not do this. – Essex Boy Jan 12 '17 at 10:55
  • @posthumecaver How did you end up solving this? I see you haven't accepted the answer as correct. Please post a separate answer if you were able to solve this in some other way. – rineez Jan 03 '22 at 06:29
  • Unfortunately there is still no standart solution for this, what we end up doing, at every release start, we are deleting from our local maven repoisotry all SNAPSHOT dependencies, we Zip the the rest of the dependencies, then jenkins in the next build start unzip this file and place it to its local repository (with groovy scripts :( ) and then start the build, this file is around 500 MB big for us, so we dont have to transport this everytime over the network, it is not nice, but this is the only solution we have at the moment.. – posthumecaver Jan 03 '22 at 08:13

1 Answers1

0

There is currently no way to achieve this, and yes, I agree with the sentiment.

A reasonably recent versions of Jenkins' Maven plugin allow you to specify a custom local repository without having to edit a settings.xml file — the option is right there at the job definition screen (in the Advanced section, select Use private Maven repository).

So, what I would do is use this option, and precede the Maven build step with a script that deletes all directories, in the local private repository, which end in -SNAPSHOT.

It's repulsive, but I can't think of any other way.

Isaac
  • 16,458
  • 5
  • 57
  • 81