【问题标题】:Control order in which jars are added to shaded jar控制将罐子添加到阴影罐子的顺序
【发布时间】:2018-06-16 20:34:42
【问题描述】:

我发现 Confluent Kafka Connect 插件只有在 jar 以特定顺序添加到类路径时才能工作。

因此,我正在尝试构建一个包含 jar 的单个阴影 jar,以相同的顺序选择冲突的类。

我的问题是如何控制罐子添加到阴影罐子的顺序?

我发现 Maven 按以下顺序处理 jar:

  1. 我的 pom 中指定的第一个依赖项
  2. 从 1 开始的 pom 的依赖关系,按照它们在 pom 中出现的顺序,除非我的 pom 中存在依赖关系,在这种情况下它会等到轮到它
  3. 我的 pom 中的下一个依赖项
  4. 2 但至于之前的依赖
  5. 迭代 3-5 直到处理完所有依赖项。

我相信这是基于订单罐子列在下面的列表中(包括用于识别的列表;我已将其截断,因为它不是特别有启发性):

[INFO] --- maven-shade-plugin:2.1:shade (default) @ kafka-connect-plus ---
[INFO] Including org.apache.hadoop:hadoop-common:jar:2.7.3 in the shaded jar.
[INFO] Excluding com.google.guava:guava:jar:11.0.2 from the shaded jar.
[INFO] Excluding org.apache.commons:commons-math3:jar:3.1.1 from the shaded jar.
[INFO] Excluding xmlenc:xmlenc:jar:0.52 from the shaded jar.
[INFO] Excluding commons-httpclient:commons-httpclient:jar:3.1 from the shaded jar.
[INFO] Excluding commons-codec:commons-codec:jar:1.4 from the shaded jar.
[INFO] Excluding commons-net:commons-net:jar:3.1 from the shaded jar.
[INFO] Excluding javax.servlet:servlet-api:jar:2.5 from the shaded jar.
[INFO] Excluding org.mortbay.jetty:jetty:jar:6.1.26 from the shaded jar.
[INFO] Excluding org.mortbay.jetty:jetty-util:jar:6.1.26 from the shaded jar.
[INFO] Excluding javax.servlet.jsp:jsp-api:jar:2.1 from the shaded jar.

我的阴影插件片段:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.1</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <artifactSet>
            <includes>
              <include>org.apache.hadoop:hadoop-common</include>
              <include>org.apache.avro:avro-ipc</include>
              <include>org.apache.parquet:parquet-avro</include>
              <include>io.confluent:kafka-avro-serializer</include>
              <include>org.apache.avro:avro</include>
              <include>org.apache.avro:avro-mapred</include>
              <include>io.confluent:kafka-connect-avro-converter</include>
              <include>io.confluent:kafka-schema-registry-client</include>
              <include>io.confluent:common-utils</include>
              <include>io.confluent:common-config</include>
            </includes>
          </artifactSet>
          <filters>
            <filter>
              <artifact>*:*</artifact>
              <excludes>
                <exclude>META-INF/*.SF</exclude>
                <exclude>META-INF/*.DSA</exclude>
                <exclude>META-INF/*.RSA</exclude>
              </excludes>
            </filter>
          </filters>
        </configuration>
      </execution>
    </executions>
  </plugin>

(这还不是罐子的完整列表)。

从上面可以看出,jar处理的顺序并不遵循include标签的顺序。

【问题讨论】:

    标签: maven maven-3 maven-shade-plugin uberjar fatjar


    【解决方案1】:

    再次阅读我的问题,我意识到上述过程完全实现了我想要的,一旦我完成了将直接依赖项列入白名单的过程:我的依赖项按照它们在依赖项部分中指定的顺序排列。

    【讨论】:

      猜你喜欢
      • 2018-06-23
      • 2012-09-03
      • 1970-01-01
      • 1970-01-01
      • 2016-08-06
      • 1970-01-01
      • 1970-01-01
      • 2019-03-03
      • 1970-01-01
      相关资源
      最近更新 更多