转载

guava&hive-exec冲突解决

maven-shade插件解决,如下为plugin配置:

<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详解

  1. 引用之后需要注意排掉log4j相关包,并且排除掉hive-exec的包,因为经过mvn-shade插件之后会将hive-exec包打成一个新的shade包,和hive-exec包无关了需要直接排掉;
guava&amp;hive-exec冲突解决
原文  https://juejin.im/post/5e9545e5f265da47b27d94d6
正文到此结束
Loading...