2016-08-24 47 views
3

我想用Spark 1.6.2,Cassandra 3和Cassandra連接器1.6構建一個使用maven的項目。Spark和Cassandra使用Maven的番石榴衝突

我發現這個問題是卡桑德拉使用番石榴+ 16V和14V星火所以當我嘗試執行,殼給我一個錯誤,我必須使用和番石榴版本+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> 

我嘗試添加番石榴依賴但不起作用。

任何人都知道如何解決它?我應該停止使用maven並使用sbt嗎?

謝謝!

回答

3

我終於明白了。萊什金如何說,這是必要的陰影的依賴。

這是我用來解決它的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> 

我希望它可以幫助別人。

謝謝!

1

最近我有同樣的問題,但與SBT。我發現這個職位非常有幫助:https://hadoopist.wordpress.com/2016/05/22/how-to-connect-cassandra-and-spark/

所以,我已經添加

assemblyShadeRules in assembly := Seq(ShadeRule.rename("com.google.**" -> "[email protected]").inAll)

我SBT構建文件來解決這個問題。在我的情況下,我創建了一個包含所有Spark和Cassandra依賴項的胖jar(sbt assembly plugin)。

我認爲你可以使用Maven shade插件來實現相同的結果(如果切換到SBT是一個問題)。