Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven build microservice with lib in another repository

we have spring microservices in separated git repositories. These microservices use shared library, which is separated repository as well. This library is used as artifact in dependencies in pom. Can you tell me how to configure jenkins to build any microservice with that library as first? This library should be build as prerequisite of build of any microservice but I don't know how to manage it.

Should we handle it in maven or in jenkins? Thank you in advice.

like image 726
Denis Stephanov Avatar asked Oct 15 '25 13:10

Denis Stephanov


2 Answers

I assume that your are using jenkins pipelines for your CI/CD. So in any case you have to create two jenkins pipelines 1st to build your library, 2nd one to build your microservice.

The way I would do it:

1) Commit code to library

2) Library build was triggered and new artifact version was generated.

3) Copy version of generated lib artifact

4) Change pom file in service and commit.

5) Micro service is getting built using new lib version.

This approach is not fully automated, but is pretty straightforward. Since you change your library rarely it's perfectly fine to set lib version manually.

The way I would try to automate it and problems we need to solve:

  • Run lib build before service build.

    We will trigger lib build for each commit to lib git repo. So you don't have to build it again.

  • Get library triggered build version and update microservice pom file with new version

    During lib build you can append lib version number to jenkins build info( e.g. build displayed name). And then pull this info during microservice build. Once you have the number you can update your pom file and start build.

Only one advantage that I see is that you are not required to set lib version manually. It will be pulled from lib jobs results.

Disadvantages:

  • complicated build
  • no control over build version update ( it will pull latest version all the time, unless you will create some mechanism to decide whether you want to retain existing lib version -> more complicated build)

  • problems with local build, since version that is in GIT and actual version of jar are different ( since you update it on the fly during jenkins job, unless you will commit version update changes right from jenkins -> complicted build).

like image 130
Ivan Lymar Avatar answered Oct 18 '25 04:10

Ivan Lymar


If you use a SNAPSHOT version of your common library during development phase, you don't need to keep updating the microservice pom with the common library version for every change in the library. Maven can retrieve the latest version of the SNAPSHOT based on timestamp everytime from the remote repository (e.g -U command line option, or once per day by default). While creating a release branch, remove SNAPSHOT and update microservice pom with the release version of the common library.

like image 38
Saptarshi Basu Avatar answered Oct 18 '25 03:10

Saptarshi Basu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!