我发现 Confluent Kafka Connect 插件只有在 jar 以特定顺序添加到类路径时才有效。
因此,我正在尝试构建一个包含 jar 的单个阴影 jar,以相同的顺序选择冲突的类。
我的问题是如何控制将罐子添加到阴影罐子的顺序?
我发现Maven按以下顺序处理jar:
- 我的 pom 中指定的第一个依赖项
- 从1开始的pom的依赖关系,按照它们出现在pom中的顺序,除非我的pom中存在依赖关系,在这种情况下它会等到轮到它
- 我的 pom 中的下一个依赖项
- 2 但至于先前的依赖
- 迭代 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
标签的顺序。