guava&hive-exec衝突解決

緣由:

解決:

maven-shade插件解決,以下爲plugin配置:apache

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <keepDependenciesWithProvidedScope>false</keepDependenciesWithProvidedScope>
                    <promoteTransitiveDependencies>false</promoteTransitiveDependencies>
                    <createDependencyReducedPom>true</createDependencyReducedPom>
                    <minimizeJar>false</minimizeJar>
                    <createSourcesJar>false</createSourcesJar>
                </configuration>

                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>

                        <configuration>
                            <artifactSet>
                                <includes>
                                    <include>org.apache.hive:hive-exec</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>

                            <relocations>
                                <relocation>
                                    <pattern>com.google.guava</pattern>
                                    <shadedPattern>com.medata.google.guava</shadedPattern>
                                </relocation>
                                <relocation>
                                    <pattern>com.google.common</pattern>
                                    <shadedPattern>com.medata.google.common</shadedPattern>
                                </relocation>
                            </relocations>

                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer" />
                            </transformers>

                        </configuration>
                    </execution>
                </executions>
複製代碼

遇到的問題:

  1. 因爲本項目要求hive shade包不能引出去,全部在多個module中分別引用;因爲單獨引用hive-shade包會致使工程內引用hive-exec的包的地方會找不到引用,此時須要作兩個操做:
  • (1)單獨install hive-shade包
  • (2)在module中在單獨引用hive-exec而且修改scope爲provide (表示此依賴參與編譯、測試,在打包時exculde)

maven scope詳解bash

  1. 引用以後須要注意排掉log4j相關包,而且排除掉hive-exec的包,由於通過mvn-shade插件以後會將hive-exec包打成一個新的shade包,和hive-exec包無關了須要直接排掉;

相關文章
相關標籤/搜索