Maven:自定义.jar在引用时无法解析正确的依赖项

时间:2019-05-25 02:16:56

标签: java maven spring-boot

我正在为应用程序构建一些自定义的Spring Boot Starter依赖项。我已经完成了一些,但是遇到了一个我从未遇到过的问题。而且我认为这与我使用Maven打包自定义依赖项有关。

正在打包的项目的pom.xml如下所示:

   <?xml version="1.0" encoding="UTF-8"?>
   <project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <groupId>com.ej.gws.starters</groupId>
    <artifactId>mapr-producer-spring-boot-starter</artifactId>
    <version>1.0.0-SNAPSHOT</version>

    <properties>
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <maprfs-path>/opt/mapr/lib/maprfs-6.0.1-mapr.jar</maprfs-path>
        <ojai-driver-path>/opt/mapr/lib/mapr-ojai-driver-6.0.1-mapr.jar</ojai-driver-path>
        <flex-json-path>/opt/mapr/lib/flexjson-2.1.jar</flex-json-path>
    </properties>

    <repositories>
        <repository>
            <id>mapr-proxy</id>
            <name>MapR Releases</name>
            <url>http://<Internal Nexus Repository>.com/content/repositories/MapR/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <dependencies>
        <!-- Spring Boot Starter Dependencies -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <!-- Web Exception Handler -->
        <dependency>
            <groupId>com.ej.gws.starters</groupId>
            <artifactId>web-exception-handler-spring-boot-starter</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </dependency>

        <!-- JSON Parser -->
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20180813</version>
        </dependency>

         <!--Kafka Client Library for MapR Streams 6.0.1-->
        <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>kafka-clients</artifactId>
            <version>1.0.1-mapr-1803-streams-6.0.1</version>
            <exclusions>
                <!-- Do not package maprfs jar, as per MapR Documentation -->
                <exclusion>
                    <groupId>com.mapr.hadoop</groupId>
                    <artifactId>maprfs</artifactId>
                </exclusion>
                <!-- Exclude slf4j transitive dependency to avoid warnings about duplicates -->
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

         <!--Needed by MapR Streams, provided by system Client Library-->
        <dependency>
            <groupId>com.mapr.hadoop</groupId>
            <artifactId>maprfs</artifactId>
            <version>6.0.1-mapr</version>
            <scope>system</scope>
            <systemPath>${maprfs-path}</systemPath>
        </dependency>
        <dependency>
            <groupId>com.mapr.ojai</groupId>
            <artifactId>mapr-ojai-driver</artifactId>
            <version>6.0.1-mapr</version>
            <scope>system</scope>
            <systemPath>${ojai-driver-path}</systemPath>
        </dependency>
        <dependency>
            <groupId>net.sf.flexjson</groupId>
            <artifactId>flexjson</artifactId>
            <version>2.1</version>
            <scope>system</scope>
            <systemPath>${flex-json-path}</systemPath>
        </dependency>
    </dependencies>
</project>

我遇到的问题与org.apache.kafka:kafka-clients:1.0.1-mapr-1803-streams-6.0.1依赖性有关。

在正在构建.jar的项目中,该依赖关系看起来像来自Maven: enter image description here

但是,在运行mvn install并生成工件之后,当我在另一个应用程序中引用它时,该依赖关系如下所示: enter image description here

所以,我要问的问题是,我该如何编写我的应用程序pom.xml,以便当另一个应用程序引用它时,它会导入完全相同的工件和版本?

此外,为了澄清,我不想建立一个胖/胖的罐子。

1 个答案:

答案 0 :(得分:0)

否,除非您拥有对另一个应用程序的完全访问权限,否则您将无法控制。如果是这样,您需要手动排除一些重复的依赖项,例如:

@media only screen and (max-width: 767px) {
  .centertext .wpb_wrapper h1 {
     text-align:center !important;
  }
  .centertext .wpb_wrapper h2 {
     text-align:center !important;
  }
  .centertext .wpb_wrapper h3 {
     text-align:center !important;
  }
  .centertext .wpb_wrapper p {
     text-align:center !important;
  }
}

顺便说一句,使用

<dependency>
      <groupId>sample.ProjectA</groupId>
      <artifactId>Project-A</artifactId>
      <version>1.0</version>
      <scope>compile</scope>
      <exclusions>
        <exclusion>  <!-- declare the exclusion here -->
          <groupId>sample.ProjectB</groupId>
          <artifactId>Project-B</artifactId>
        </exclusion>
      </exclusions> 
    </dependency>

经常说出实际的依赖性是什么。