【问题标题】:Spark and Cassandra Guava conflict using MavenSpark 和 Cassandra Guava 使用 Maven 冲突
【发布时间】:2016-12-31 07:01:22
【问题描述】:

我正在尝试使用带有 Spark 1.6.2、Cassandra 3 和 Cassandra 连接器 1.6 的 maven 构建项目。

我发现的问题是 Cassandra 使用 Guava +16v 和 Spark 14v 所以当我尝试执行时,shell 给我一个错误,我必须使用和 Guava 版本 +16

我在maven中的依赖是:

        <!--Spark dependencies -->
    <dependency>
        <groupId>org.apache.spark</groupId>
        <artifactId>spark-core_2.10</artifactId>
        <version>1.6.2</version>
    </dependency>

    <!--Cassandra dependencies-->
    <dependency>
        <groupId>org.apache.cassandra</groupId>
        <artifactId>cassandra-all</artifactId>
        <version>3.0.2</version>
    </dependency>
    <dependency>
        <groupId>com.datastax.spark</groupId>
        <artifactId>spark-cassandra-connector_2.10</artifactId>
        <version>1.6.0</version>
    </dependency>

我尝试添加 Guava 依赖但不起作用。

有人知道怎么解决吗?我应该停止使用 maven 并使用 sbt 吗?

谢谢!!

【问题讨论】:

    标签: maven apache-spark cassandra guava


    【解决方案1】:

    我终于明白了。 leshkin 怎么说的,需要遮蔽依赖。

    这是我用来解决它的maven代码!

          <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>net.alchim31.maven</groupId>
                    <artifactId>scala-maven-plugin</artifactId>
                    <version>3.2.2</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugin</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.5.1</version>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>scala-compile-first</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>add-source</goal>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>scala-test-compile</id>
                        <phase>process-test-resources</phase>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.4.3</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>
                                shade
                            </goal>
                        </goals>
                    </execution>
                </executions>
    
                <configuration>
                    <minimizeJar>true</minimizeJar>
                    <shadedArtifactAttached>true</shadedArtifactAttached>
                    <shadedClassifierName>fat</shadedClassifierName>
    
                    <relocations>
                        <relocation>
                            <pattern>com.google</pattern>
                            <shadedPattern>shaded.guava</shadedPattern>
                            <includes>
                                <include>com.google.**</include>
                            </includes>
    
                            <excludes>
                                <exclude>com.google.common.base.Optional</exclude>
                                <exclude>com.google.common.base.Absent</exclude>
                                <exclude>com.google.common.base.Present</exclude>
                            </excludes>
                        </relocation>
                    </relocations>
    
                    <filters>
                        <filter>
                            <artifact>*:*</artifact>
                            <excludes>
                                <exclude>META-INF/*.SF</exclude>
                                <exclude>META-INF/*.DSA</exclude>
                                <exclude>META-INF/*.RSA</exclude>
                            </excludes>
                        </filter>
                    </filters>
    
                </configuration>
            </plugin>
            <!-- Plugin to create a single jar that includes all dependencies -->
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    

    我希望它可以帮助某人。

    谢谢!!

    【讨论】:

    • 为什么要排除 Optional、Absent、Present?对这些类进行着色是否有问题
    【解决方案2】:

    我最近遇到了同样的问题,但使用的是 SBT。我发现这篇文章很有帮助:https://hadoopist.wordpress.com/2016/05/22/how-to-connect-cassandra-and-spark/

    所以,我已经添加了

    assemblyShadeRules in assembly := Seq(ShadeRule.rename("com.google.**" -&gt; "shadeio.@1").inAll)

    到我的 SBT 构建文件来解决问题。在我的例子中,我创建了一个包含所有 Spark 和 Cassandra 依赖项的胖 jar(sbt 程序集插件)。

    我认为您可以使用 maven shade 插件来实现相同的结果(如果切换到 SBT 是一个问题)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-07
      • 1970-01-01
      • 1970-01-01
      • 2019-06-21
      • 2017-04-20
      • 2017-06-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多