How can I organize the project code, which is designed for several versions of the library

I am writing a small L1 library, which depends on a third-party L2 library. L2 has several versions that L1 must support. Each version of L2 associated with a specific API and target JDK. I do not control L2 .

For instance:

  • L2-v1.x I need to provide L1-v1.x
  • L2-v2.x β†’ I need to provide L1-v2.x
  • L2-v3.x β†’ I need to provide L1-v3.x

What would be the best way to arrange the code in git (what should I put in master / what branch / should have several projects / several modules), knowing that I need to build the project using Maven, and I want to build as easy as possible?

Thanks in advance.

Edit: All versions of L2 are in Maven Central, all versions of L1 must be in Central.

+5
source share
1 answer

If these library sources are not in the maven repository, you can follow " Using Git Submodules for Maven Artifacts Out of Center ".
Git submodules are great for linking a repo repository version to another.

Here is a version adapted to your setup:

  • You configure the Maven project to the parent pom and your own L1 project as the Maven module of this project.

  • You import the project you want into your project. For example, the L2 project in the right tag .

 git submodule add /url/to/L2.git cd L2 git checkout <L2-vy.x> cd .. git add . git commit -m "Add submodule L2 at <L2-vy.x>" git push 

The git submodule will now clone the L2 repository in a folder named L2.
Git will add a .gitmodule file that looks like this:

submodule ["L2"] path = L2 url = / url / to / L2.git

The directory structure should look like this

 yourParentProject - pom.xml - .git - .gitmodule - L1 \- pom.xml - L2 \- pom.xml 
  1. In the parent pom.xml, you add the L2 folder as a module.
 <modules> <module>L1</module> <module>L2</module> </modules> 

And in your L1 project, you add L2 as a dependency:

 <groupId>com.github.user.L2</groupId> <artifactId>L2</artifactId> <version>L2-vy.x</version> 
  1. Now everything is set up. If you call mvm test in the parent project, you will see that it builds L2 first, and then your L1 project.

Using

When other developers clone your project, they also need to install the module using the Git command:

 git submodule update --init 
+1
source

Source: https://habr.com/ru/post/1232671/


All Articles