您应该创建 2 个配置文件。1 用于您在编译范围内使用 spark 的想法(默认),另一个在构建期间使用(具有提供的范围)。
<profiles>
<profile>
<id>default-without-spark</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</profile>
<profile>
<id>dev</id>
<dependencies>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
</dependency>
</dependencies>
</profile>
</profiles>
你会得到你想要的,而不会受到@maasg 解决方案的不利影响(所有 spark 传递依赖项都添加到你的最终 jar 中)