在 IDEA 中运行 Spark 程序报错:Multiple sources found for text.......please specify the fully qualified class name

报错如图:

在 IDEA 中运行 Spark 程序报错:Multiple sources found for text.......please specify the fully qualified class name

代码很简单,就是官方的示例:

在 IDEA 中运行 Spark 程序报错:Multiple sources found for text.......please specify the fully qualified class name

经过多次搜索无果后,想到可能是引用了多个不同 jar 包导致的,于是查看左侧的 External Libraries,发现确实有两个不同的 spark-sql 包:

在 IDEA 中运行 Spark 程序报错:Multiple sources found for text.......please specify the fully qualified class name
这是 ${SPARK_HOME}/jars 下的

在 IDEA 中运行 Spark 程序报错:Multiple sources found for text.......please specify the fully qualified class name
这是 maven 引进来的,可以看到版本不同

去掉其中一个就可以