background

  • Recently, in response to the company’s request, an internal shared two-party library package was developed. Here under the popular science: what is a party library, two square library, three – party library. In alibaba’s Taishan version “Java Development Manual” attached 2: proper nouns in the chapter is mentioned

  • Party library: the library (JAR package) that subproject modules depend on in this project

It depends on the common module inside the project, which usually defines some basic functions that all modules will use, such as global exception code, distributed lock, unified response entity and so on

  • Binary libraries: libraries (JARS) that are distributed internally to a central repository for other applications within the company to rely on.

In Internet companies there are usually divisions, and then there is a division called base department/base center, which may provide some of the company’s base class libraries, eg: unified AMQP operations for MQ, unified DUbbo operations for RPC, and so on. Eventually, these will be pushed to the Maven repository in the form of JAR packages (the company needs to set up its own Maven repository). Now is the era of Spring Boot. If the company uses The System of SpringBoot, these JAR packages are usually provided in the way of starter. By using the automatic assembly mechanism of SpringBoot, other business units can easily connect with each other.

  • Third-party libraries: Open source libraries outside the company (JAR packages)

Common Springboot, Mybatis

Because of the internal use of the Technology stack related to SpringBoot, the binary-library package I developed is provided as a starter. The entire docking process requires only two steps:

1. It is necessary to push the two-party library package to maven repository

2. Other business units only need to add maven coordinates of the two-party library package

There are a few minor details here: the binary library package is a project, and there are some binary and tripartite cases that depend on it. Generally, the scope of the jar packages that are internally dependent on the two libraries is set to Provider (the default system has provided the jars and does not coupling the jars with the project of the pair). However, there may be cases where there is no added dependency on the pair, so you need to add a dependency that is consistent with the system version of the pair. To understand how to find the right version of Spring-Kafka, look at a case study of springBoot introducing Spring-Kafka.

Why can’t Maven find a version of Spring-Kafka?

  • Consider a scenario where I develop a two-party library package using a technology stack called SpringBoot, and one of the internally developed features relies on spring-Kafka’s three-party library. As we all know, SpringBoot provides us with an extremely comfortable development environment. When we introduced the SpringBoot framework, it internally defined all the three-party library dependencies that fit the current version. Therefore, if we want to introduce the Spring-Kafka module, we just need to add the following coordinates to the pom.xml file:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.4</version>
        <relativePath/> <! -- lookup parent from repository -->
    </parent>
    
    <! -- add the following coordinates without specifying the version -->
    <dependencies>
        <dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka</artifactId>
        </dependency>
    </dependencies>
    Copy the code

    When we introduced the Spring-Kafka module above, we did not specify that version can also be used. This is because the spring-Kafka dependency is defined in the Spring-boot-starter -parent dependencyManagement system. As a submodule, the version number is inherited from the parent project definition by default. If you use springBoot 1.4.1.RELEASE for your client, you will find that there is no spring-Kafka version for Maven:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.1. RELEASE</version>
        <relativePath/> <! -- lookup parent from repository -->
    </parent>
    
    <! -- add the following coordinates without specifying the version -->
    <dependencies>
        <dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka</artifactId>
        </dependency>
    </dependencies>
    Copy the code

    The general reason for this is that there is no internal dependency on Spring-Kafka in the Spring-boot-starter parent, so it cannot inherit the version defined by the parent class, and maven will eventually tell you that no version can be found. It is not possible to upgrade springBoot to integrate with your dual library, is it? Therefore, we need to find the right version of Spring-Kafka for the peer.

How do I find the dependencies inside springboot 1.4.1.RELEASE

  • One of the easiest ways is to find the corresponding POM file definition in IDEA, which is one way. However, as a two-party library provider, you will often have to deal with the problem of not being able to introduce Spring-Kafka due to different versions of SpringBoot on the business side. Do we want to change the springBoot version of Maven locally, download it from Maven and then use idea to view it? This is obviously a bit of a problem.

  • Another option is to find the official SpringBoot 1.4.1.RELEASE documentation, but kafka is not even included in maven dependencies, most likely because kafka is not integrated in this RELEASE.

  • Another way is: refer to this link repo1.maven.org/maven2/org/… . In this link, there are dependencies for all versions of SpringBoot. Now we want to see which libraries springBoot internally depends on. We can locate them like this:

    1. Positioning version

    2. View dependent POM files

    3. Be good at searching (search spring-Kafka)

      As you can see, there is no internal dependency on Spring-Kafka in springBoot 1.4.1.RELEASE. What to do now? Update the SpringBoot version and continue to search, eventually you will find that there is an internal dependency on Spring-Kafka in 1.5.0.release. Therefore, we can try to introduce the found version 1.1.2.release into Maven

      The corresponding pom. XML file is

      <dependency>
          <groupId>org.springframework.kafka</groupId>
          <artifactId>spring-kafka</artifactId>
          <version>1.1.2. The RELEASE</version>
      </dependency>
      Copy the code

    In this scenario, the introduction of 1.1.2.RELEASE will resolve the problem and the peer’s system will work properly.

    Maybe this way is not applicable in other scenes, but it is a kind of way, we can through repo1.maven.org/maven2/org/…

Third, summary

  • Another solution for locating dependent versions. if you find my post useful, please like, bookmark and follow. :laughing:
  • I’m a slow walker, but I never walk backwards