【问题标题】:Submit job to spark with conflicting jackson dependencies?提交作业以引发冲突的杰克逊依赖项?
【发布时间】:2017-03-08 05:14:27
【问题描述】:

我创建了一个使用 jackson 2.7.5 的 uber-jar。我正在使用 spark 1.6.2(因为我在 scala-2.10 上)。但是,每当我尝试提交我的 spark 作业时,我都会收到有关在更高版本的杰克逊版本中的功能开关上找不到方法的错误。

我会假设一个 uber-jar 将允许我捆绑我自己的依赖项,即使它们与使用某种委托类加载器来隔离冲突需要运行的 spark 冲突。不是这样吗?如果不是,我该如何解决这个问题?

我知道有这个答案java.lang.NoSuchMethodError Jackson databind and Spark 基本上建议使用 sparks jackson 而不是你自己的,但是 spark 的 jackson 现在已经很老了,我有依赖于新 jackson 功能的代码

【问题讨论】:

  • 我的 jars 会优先于 sparks 类路径吗? 8个;不是那么这不会有所作为吗?它显然是从自己的类路径中获取杰克逊,而不是先让我加载自己的版本
  • 我正面临一个类似的问题,即通过作业和作业服务器引用了多个 netty 版本。你能解决这个问题吗?
  • 我最终提取了 spark 源代码并更新了它们的依赖关系并创建了自定义构建

标签: json scala apache-spark jackson


【解决方案1】:

您需要遮蔽依赖关系,以便两个版本可以共存。您的较新版本路径名称将被更改以解决冲突。

如果您使用的是 Maven:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

  <groupId><!-- YOUR_GROUP_ID --></groupId>
  <artifactId><!-- YOUR_ARTIFACT_ID --></artifactId>
  <version><!-- YOUR_PACKAGE_VERSION --></version>

  <dependencies>

    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-sql_2.11</artifactId>
      <version><!-- YOUR_SPARK_VERSION --></version>
      <scope>provided</scope>
    </dependency>
    <!-- YOUR_DEPENDENCIES -->
  </dependencies>
  <build>
    <plugins>

      <plugin>
        <groupId>net.alchim31.maven</groupId>
        <artifactId>scala-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>testCompile</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <scalaVersion><!-- YOUR_SCALA_VERSION --></scalaVersion>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <mainClass><!-- YOUR_APPLICATION_MAIN_CLASS --></mainClass>
                </transformer>
              </transformers>
              <filters>
                <filter>
                  <artifact>*:*</artifact>
                  <excludes>
                    <exclude>META-INF/maven/**</exclude>
                    <exclude>META-INF/*.SF</exclude>
                    <exclude>META-INF/*.DSA</exclude>
                    <exclude>META-INF/*.RSA</exclude>
                  </excludes>
                </filter>
              </filters>
              <relocations>
                <relocation>
                  <pattern>com</pattern>
                  <shadedPattern>repackaged.com.google.common</shadedPattern>
                  <includes>
                    <include>com.google.common.**</include>
                  </includes>
                </relocation>
              </relocations>
            </configuration>
          </execution>
        </executions>
      </plugin>

    </plugins>
  </build>

</project>

来源:https://cloud.google.com/dataproc/docs/guides/manage-spark-dependencies

【讨论】:

    【解决方案2】:

    如果使用--conf spark.driver.extraClassPathspark.executor.extraClassPath 是可能的。

    请看我的回复here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-12
      • 1970-01-01
      • 2015-05-24
      • 2023-04-03
      • 2015-04-19
      • 1970-01-01
      • 2016-09-10
      相关资源
      最近更新 更多