我正在开发一个使用 Apache Spark 处理 IMDb 数据的项目。我的设置涉及 Spark Core 和 Spark SQL 依赖项,以及用于处理 JSON 序列化和反序列化的 Jackson。我使用 Maven 来管理依赖项,并使用 Maven Shade 插件将我的应用程序打包到一个 fat JAR 中进行部署。
问题:
当我运行 Spark 应用程序时,我遇到了 Jackson 的运行时问题,特别是
jackson-databind
。依赖项中包含的 Jackson 版本之间似乎存在冲突。尽管在 pom.xml 中明确指定了版本,问题仍然存在。
环境
Java 版本:11
火花版本:3.5.1
Scala 版本:2.13
杰克逊版本:2.15.2
构建工具:Maven
错误日志
stderr
at org.apache.spark.SparkContext.withScope(SparkContext.scala:924)
at org.apache.spark.SparkContext.textFile(SparkContext.scala:1055)
at org.apache.spark.api.java.JavaSparkContext.textFile(JavaSparkContext.scala:175)
at org.example.Main.totalTvSeries(Main.java:73)
at org.example.Main.main(Main.java:47)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:569)
at org.apache.hadoop.util.RunJar.run(RunJar.java:328)
at org.apache.hadoop.util.RunJar.main(RunJar.java:241)
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Scala module 2.15.2 requires Jackson Databind version >= 2.15.0 and < 2.16.0 - Found jackson-databind version 2.12.7-1
at com.fasterxml.jackson.module.scala.JacksonModule.setupModule(JacksonModule.scala:61)
at com.fasterxml.jackson.module.scala.JacksonModule.setupModule$(JacksonModule.scala:46)
at com.fasterxml.jackson.module.scala.DefaultScalaModule.setupModule(DefaultScalaModule.scala:17)
at com.fasterxml.jackson.databind.ObjectMapper.registerModule(ObjectMapper.java:835)
at org.apache.spark.rdd.RDDOperationScope$.<clinit>(RDDOperationScope.scala:82)
... 11 more
我的pom.xml
<?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>
<groupId>org.example</groupId>
<artifactId>IMDBSpark</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- Spark Core dependency -->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.13</artifactId>
<version>3.5.1</version>
</dependency>
<!-- Spark SQL dependency -->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.13</artifactId>
<version>3.5.1</version>
</dependency>
<!-- Jackson Databind dependency -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.15.2</version>
</dependency>
<!-- Jackson Scala Module -->
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-scala_2.13</artifactId>
<version>2.15.2</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<!-- Align all Jackson dependencies to version 2.15.2 -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.15.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.15.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.15.2</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<!-- Shade plugin to create a fat JAR -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.example.Main</mainClass>
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
我尝试过的
1.对齐 Jackson 版本: 我使用 Maven 中的
dependencyManagement
部分将所有 Jackson 依赖项(jackson-databind
、jackson-core
、jackson-annotations
)与版本 2.15.2
对齐。
2。检查传递依赖冲突: 我运行了 mvn dependency:tree 并发现 Spark 中的一些传递依赖包含旧版本的 Jackson。我在某些依赖项中使用了
<exclusion>
来删除 jackson-databind
。
我需要什么帮助:
如何解决基于 Maven 的项目中 Jackson 和 Spark 依赖项之间的冲突?