引用 google-play-services.jar

本文详细介绍了如何通过修改Eclipse的eclipse.ini文件中的-Xms和-Xmx参数来解决Eclipse编译时卡死的问题。通过调整初始堆内存和最大堆内存的大小,可以有效提升Eclipse的性能,防止卡死现象发生。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

@integer/google_play_services_version 需要项目依赖sdk下的google-play-services_lib


编译时eclipse卡死,修改eclipse\eclipse.ini

-Xms256m
-Xmx1024m

sbt:spark-app> assembly [warn] multiple main classes detected: run 'show discoveredMainClasses' to see the list [error] 37 error(s) were encountered during the merge: [error] stack trace is suppressed; run last assembly for the full output [error] (assembly) [error] Deduplicate found different file contents in the following: [error] Jar name = protobuf-java-3.19.6.jar, jar org = com.google.protobuf, entry target = google/protobuf/api.proto [error] Jar name = spark-core_2.12-3.5.0.jar, jar org = org.apache.spark, entry target = google/protobuf/api.proto [error] Deduplicate found different file contents in the following: [error] Jar name = protobuf-java-3.19.6.jar, jar org = com.google.protobuf, entry target = google/protobuf/field_mask.proto [error] Jar name = spark-core_2.12-3.5.0.jar, jar org = org.apache.spark, entry target = google/protobuf/field_mask.proto [error] Deduplicate found different file contents in the following: [error] Jar name = commons-logging-1.1.3.jar, jar org = commons-logging, entry target = org/apache/commons/logging/Log.class [error] Jar name = jcl-over-slf4j-2.0.7.jar, jar org = org.slf4j, entry target = org/apache/commons/logging/Log.class [error] Deduplicate found different file contents in the following: [error] Jar name = protobuf-java-3.19.6.jar, jar org = com.google.protobuf, entry target = google/protobuf/struct.proto [error] Jar name = spark-core_2.12-3.5.0.jar, jar org = org.apache.spark, entry target = google/protobuf/struct.proto [error] Deduplicate found different file contents in the following: [error] Jar name = commons-logging-1.1.3.jar, jar org = commons-logging, entry target = org/apache/commons/logging/impl/NoOpLog.class [error] Jar name = jcl-over-slf4j-2.0.7.jar, jar org = org.slf4j, entry target = org/apache/commons/logging/impl/NoOpLog.class [error] Deduplicate found different file contents in the following: [error] Jar name = arrow-format-11.0.0.jar, jar org = org.apache.arrow, entry target = arrow-git.properties [error] Jar name = arrow-memory-core-11.0.0.jar, jar org = org.apache.arrow, entry target = arrow-git.properties [error] Jar name = arrow-memory-netty-11.0.0.jar, jar org = org.apache.arrow, entry target = arrow-git.properties [error] Jar name = arrow-vector-11.0.0.jar, jar org = org.apache.arrow, entry target = arrow-git.properties [error] Deduplicate found different file contents in the following: [error] Jar name = javax.inject-1.jar, jar org = javax.inject, entry target = javax/inject/Singleton.class [error] Jar name = jakarta.inject-2.6.1.jar, jar org = org.glassfish.hk2.external, entry target = javax/inject/Singleton.class [error] Deduplicate found different file contents in the following: [error] Jar name = protobuf-java-3.19.6.jar, jar org = com.google.protobuf, entry target = google/protobuf/duration.proto [error] Jar name = spark-core_2.12-3.5.0.jar, jar org = org.apache.spark, entry target = google/protobuf/duration.proto [error] Deduplicate found different file contents in the following: [error] Jar name = javax.inject-1.jar, jar org = javax.inject, entry target = javax/inject/Named.class [error] Jar name = jakarta.inject-2.6.1.jar, jar org = org.glassfish.hk2.external, entry target = javax/inject/Named.class [error] Deduplicate found different file contents in the following: [error] Jar name = javax.inject-1.jar, jar org = javax.inject, entry target = javax/inject/Inject.class [error] Jar name = jakarta.inject-2.6.1.jar, jar org = org.glassfish.hk2.external, entry target = javax/inject/Inject.class [error] Deduplicate found different file contents in the following: [error] Jar name = commons-logging-1.1.3.jar, jar org = commons-logging, entry target = org/apache/commons/logging/LogFactory.class [error] Jar name = jcl-over-slf4j-2.0.7.jar, jar org = org.slf4j, entry target = org/apache/commons/logging/LogFactory.class [error] Deduplicate found different file contents in the following: [error] Jar name = commons-logging-1.1.3.jar, jar org = commons-logging, entry target = org/apache/commons/logging/LogConfigurationException.class [error] Jar name = jcl-over-slf4j-2.0.7.jar, jar org = org.slf4j, entry target = org/apache/commons/logging/LogConfigurationException.class [error] Deduplicate found different file contents in the following: [error] Jar name = jakarta.annotation-api-1.3.5.jar, jar org = jakarta.annotation, entry target = javax/annotation/security/DenyAll.class [error] Jar name = jsr250-api-1.0.jar, jar org = javax.annotation, entry target = javax/annotation/security/DenyAll.class [error] Deduplicate found different file contents in the following: [error] Jar name = protobuf-java-3.19.6.jar, jar org = com.google.protobuf, entry target = google/protobuf/timestamp.proto [error] Jar name = spark-core_2.12-3.5.0.jar, jar org = org.apache.spark, entry target = google/protobuf/timestamp.proto [error] Deduplicate found different file contents in the following: [error] Jar name = jakarta.annotation-api-1.3.5.jar, jar org = jakarta.annotation, entry target = javax/annotation/Generated.class [error] Jar name = jsr250-api-1.0.jar, jar org = javax.annotation, entry target = javax/annotation/Generated.class [error] Deduplicate found different file contents in the following: [error] Jar name = protobuf-java-3.19.6.jar, jar org = com.google.protobuf, entry target = google/protobuf/source_context.proto [error] Jar name = spark-core_2.12-3.5.0.jar, jar org = org.apache.spark, entry target = google/protobuf/source_context.proto [error] Deduplicate found different file contents in the following: [error] Jar name = protobuf-java-3.19.6.jar, jar org = com.google.protobuf, entry target = google/protobuf/empty.proto [error] Jar name = spark-core_2.12-3.5.0.jar, jar org = org.apache.spark, entry target = google/protobuf/empty.proto [error] Deduplicate found different file contents in the following: [error] Jar name = jakarta.annotation-api-1.3.5.jar, jar org = jakarta.annotation, entry target = javax/annotation/Resource.class [error] Jar name = jsr250-api-1.0.jar, jar org = javax.annotation, entry target = javax/annotation/Resource.class [error] Deduplicate found different file contents in the following: [error] Jar name = jakarta.annotation-api-1.3.5.jar, jar org = jakarta.annotation, entry target = javax/annotation/security/RolesAllowed.class [error] Jar name = jsr250-api-1.0.jar, jar org = javax.annotation, entry target = javax/annotation/security/RolesAllowed.class [error] Deduplicate found different file contents in the following: [error] Jar name = jakarta.annotation-api-1.3.5.jar, jar org = jakarta.annotation, entry target = javax/annotation/PreDestroy.class [error] Jar name = jsr250-api-1.0.jar, jar org = javax.annotation, entry target = javax/annotation/PreDestroy.class [error] Deduplicate found different file contents in the following: [error] Jar name = protobuf-java-3.19.6.jar, jar org = com.google.protobuf, entry target = google/protobuf/descriptor.proto [error] Jar name = spark-core_2.12-3.5.0.jar, jar org = org.apache.spark, entry target = google/protobuf/descriptor.proto [error] Deduplicate found different file contents in the following: [error] Jar name = commons-logging-1.1.3.jar, jar org = commons-logging, entry target = org/apache/commons/logging/impl/SimpleLog.class [error] Jar name = jcl-over-slf4j-2.0.7.jar, jar org = org.slf4j, entry target = org/apache/commons/logging/impl/SimpleLog.class [error] Deduplicate found different file contents in the following: [error] Jar name = jakarta.annotation-api-1.3.5.jar, jar org = jakarta.annotation, entry target = javax/annotation/security/DeclareRoles.class [error] Jar name = jsr250-api-1.0.jar, jar org = javax.annotation, entry target = javax/annotation/security/DeclareRoles.class [error] Deduplicate found different file contents in the following: [error] Jar name = protobuf-java-3.19.6.jar, jar org = com.google.protobuf, entry target = google/protobuf/wrappers.proto [error] Jar name = spark-core_2.12-3.5.0.jar, jar org = org.apache.spark, entry target = google/protobuf/wrappers.proto [error] Deduplicate found different file contents in the following: [error] Jar name = javax.inject-1.jar, jar org = javax.inject, entry target = javax/inject/Qualifier.class [error] Jar name = jakarta.inject-2.6.1.jar, jar org = org.glassfish.hk2.external, entry target = javax/inject/Qualifier.class [error] Deduplicate found different file contents in the following: [error] Jar name = jakarta.annotation-api-1.3.5.jar, jar org = jakarta.annotation, entry target = javax/annotation/security/PermitAll.class [error] Jar name = jsr250-api-1.0.jar, jar org = javax.annotation, entry target = javax/annotation/security/PermitAll.class [error] Deduplicate found different file contents in the following: [error] Jar name = protobuf-java-3.19.6.jar, jar org = com.google.protobuf, entry target = google/protobuf/any.proto [error] Jar name = spark-core_2.12-3.5.0.jar, jar org = org.apache.spark, entry target = google/protobuf/any.proto [error] Deduplicate found different file contents in the following: [error] Jar name = jakarta.annotation-api-1.3.5.jar, jar org = jakarta.annotation, entry target = javax/annotation/Resources.class [error] Jar name = jsr250-api-1.0.jar, jar org = javax.annotation, entry target = javax/annotation/Resources.class [error] Deduplicate found different file contents in the following: [error] Jar name = jakarta.annotation-api-1.3.5.jar, jar org = jakarta.annotation, entry target = javax/annotation/Resource$AuthenticationType.class [error] Jar name = jsr250-api-1.0.jar, jar org = javax.annotation, entry target = javax/annotation/Resource$AuthenticationType.class [error] Deduplicate found different file contents in the following: [error] Jar name = jackson-core-2.15.2.jar, jar org = com.fasterxml.jackson.core, entry target = META-INF/versions/9/module-info.class [error] Jar name = jackson-databind-2.15.2.jar, jar org = com.fasterxml.jackson.core, entry target = META-INF/versions/9/module-info.class [error] Jar name = jackson-datatype-jsr310-2.13.4.jar, jar org = com.fasterxml.jackson.datatype, entry target = META-INF/versions/9/module-info.class [error] Jar name = gson-2.10.1.jar, jar org = com.google.code.gson, entry target = META-INF/versions/9/module-info.class [error] Jar name = log4j-api-2.20.0.jar, jar org = org.apache.logging.log4j, entry target = META-INF/versions/9/module-info.class [error] Jar name = parquet-jackson-1.12.3.jar, jar org = org.apache.parquet, entry target = META-INF/versions/9/module-info.class [error] Jar name = jcl-over-slf4j-2.0.7.jar, jar org = org.slf4j, entry target = META-INF/versions/9/module-info.class [error] Jar name = slf4j-api-2.0.7.jar, jar org = org.slf4j, entry target = META-INF/versions/9/module-info.class [error] Jar name = xz-1.9.jar, jar org = org.tukaani, entry target = META-INF/versions/9/module-info.class [error] Deduplicate found different file contents in the following: [error] Jar name = protobuf-java-3.19.6.jar, jar org = com.google.protobuf, entry target = google/protobuf/type.proto [error] Jar name = spark-core_2.12-3.5.0.jar, jar org = org.apache.spark, entry target = google/protobuf/type.proto [error] Deduplicate found different file contents in the following: [error] Jar name = jakarta.annotation-api-1.3.5.jar, jar org = jakarta.annotation, entry target = javax/annotation/PostConstruct.class [error] Jar name = jsr250-api-1.0.jar, jar org = javax.annotation, entry target = javax/annotation/PostConstruct.class [error] Deduplicate found different file contents in the following: [error] Jar name = netty-all-4.1.96.Final.jar, jar org = io.netty, entry target = META-INF/io.netty.versions.properties [error] Jar name = netty-buffer-4.1.96.Final.jar, jar org = io.netty, entry target = META-INF/io.netty.versions.properties [error] Jar name = netty-codec-http2-4.1.96.Final.jar, jar org = io.netty, entry target = META-INF/io.netty.versions.properties [error] Jar name = netty-codec-http-4.1.96.Final.jar, jar org = io.netty, entry target = META-INF/io.netty.versions.properties [error] Jar name = netty-codec-socks-4.1.96.Final.jar, jar org = io.netty, entry target = META-INF/io.netty.versions.properties [error] Jar name = netty-codec-4.1.96.Final.jar, jar org = io.netty, entry target = META-INF/io.netty.versions.properties [error] Jar name = netty-common-4.1.96.Final.jar, jar org = io.netty, entry target = META-INF/io.netty.versions.properties [error] Jar name = netty-handler-proxy-4.1.96.Final.jar, jar org = io.netty, entry target = META-INF/io.netty.versions.properties [error] Jar name = netty-handler-4.1.96.Final.jar, jar org = io.netty, entry target = META-INF/io.netty.versions.properties [error] Jar name = netty-resolver-4.1.96.Final.jar, jar org = io.netty, entry target = META-INF/io.netty.versions.properties [error] Jar name = netty-transport-classes-epoll-4.1.96.Final.jar, jar org = io.netty, entry target = META-INF/io.netty.versions.properties [error] Jar name = netty-transport-classes-kqueue-4.1.96.Final.jar, jar org = io.netty, entry target = META-INF/io.netty.versions.properties [error] Jar name = netty-transport-native-epoll-4.1.96.Final.jar, jar org = io.netty, entry target = META-INF/io.netty.versions.properties [error] Jar name = netty-transport-native-epoll-4.1.96.Final.jar, jar org = io.netty, entry target = META-INF/io.netty.versions.properties [error] Jar name = netty-transport-native-epoll-4.1.96.Final.jar, jar org = io.netty, entry target = META-INF/io.netty.versions.properties [error] Jar name = netty-transport-native-kqueue-4.1.96.Final.jar, jar org = io.netty, entry target = META-INF/io.netty.versions.properties [error] Jar name = netty-transport-native-kqueue-4.1.96.Final.jar, jar org = io.netty, entry target = META-INF/io.netty.versions.properties [error] Jar name = netty-transport-native-unix-common-4.1.96.Final.jar, jar org = io.netty, entry target = META-INF/io.netty.versions.properties [error] Jar name = netty-transport-4.1.96.Final.jar, jar org = io.netty, entry target = META-INF/io.netty.versions.properties [error] Deduplicate found different file contents in the following: [error] Jar name = javax.inject-1.jar, jar org = javax.inject, entry target = javax/inject/Scope.class [error] Jar name = jakarta.inject-2.6.1.jar, jar org = org.glassfish.hk2.external, entry target = javax/inject/Scope.class [error] Deduplicate found different file contents in the following: [error] Jar name = log4j-1.2-api-2.20.0.jar, jar org = org.apache.logging.log4j, entry target = META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat [error] Jar name = log4j-core-2.20.0.jar, jar org = org.apache.logging.log4j, entry target = META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat [error] Deduplicate found different file contents in the following: [error] Jar name = javax.inject-1.jar, jar org = javax.inject, entry target = javax/inject/Provider.class [error] Jar name = jakarta.inject-2.6.1.jar, jar org = org.glassfish.hk2.external, entry target = javax/inject/Provider.class [error] Deduplicate found different file contents in the following: [error] Jar name = jakarta.annotation-api-1.3.5.jar, jar org = jakarta.annotation, entry target = javax/annotation/security/RunAs.class [error] Jar name = jsr250-api-1.0.jar, jar org = javax.annotation, entry target = javax/annotation/security/RunAs.class [error] Total time: 5 s, completed 2025年7月12日 下午12:56:20 [error] server failed to start on local:sbt-server-8814d8f5c3747ce114fe. java.io.IOException: Could not create lock for \\.\pipe\sbt-server-8814d8f5c3747ce114fe_lock, error 5 sbt:spark-app>
最新发布
07-13
<think>我们正在解决两个问题:1) 多个主类导致的警告;2) 打包时重复类文件冲突。 首先,对于多个主类的问题,通常是因为项目中有多个定义了main方法的对象。sbt assembly需要明确指定主类。 其次,重复类文件问题是因为多个依赖jar包中包含相同路径的类文件,需要定义合并策略(merge strategy)来解决冲突。 解决方案: 1. **指定主类**: 在build.sbt中通过`mainClass`设置来指定一个主类,例如: ```scala assembly / mainClass := Some("com.example.Main") ``` 或者,如果项目有多个模块,可以按模块设置: ```scala mainClass in assembly := Some("com.example.Main") ``` 2. **自定义合并策略**: sbt assembly提供了多种合并策略,常见的策略有: - `MergeStrategy.first`:选择第一个出现的文件 - `MergeStrategy.last`:选择最后一个出现的文件 - `MergeStrategy.deduplicate`:默认策略,如果所有文件内容相同则保留一个,否则报错 - `MergeStrategy.concat`:将所有文件内容连接起来 - `MergeStrategy.filterDistinctLines`:合并并去重行 - `MergeStrategy.rename`:重命名冲突的文件 我们可以在build.sbt中自定义合并策略,例如: ```scala assembly / assemblyMergeStrategy := { case PathList("META-INF", xs @ _*) => MergeStrategy.discard case x => MergeStrategy.first } ``` 上述策略表示:所有META-INF目录下的文件都丢弃(因为通常这些文件是元数据,容易冲突);其他文件则选择第一个出现的。 但是,对于某些特定的冲突文件,我们可能需要更具体的策略。例如,对于`reference.conf`文件(Typesafe配置库使用),我们通常需要合并所有内容: ```scala assembly / assemblyMergeStrategy := { case PathList("META-INF", xs @ _*) => MergeStrategy.discard case "reference.conf" => MergeStrategy.concat case x => MergeStrategy.first } ``` 3. **处理常见的冲突**: - **META-INF/MANIFEST.MF**:通常我们不需要,可以丢弃(使用`MergeStrategy.discard`)或使用`MergeStrategy.rename`。 - **META-INF/services/**:这些是Java服务加载器使用的文件,需要合并(使用`MergeStrategy.concat`或`MergeStrategy.filterDistinctLines`)。 - **META-INF/spring.schemas**和**META-INF/spring.handlers**:Spring相关的文件,需要合并(`MergeStrategy.concat`或`MergeStrategy.filterDistinctLines`)。 一个更完整的合并策略示例: ```scala assembly / assemblyMergeStrategy := { case PathList("META-INF", "services", xs @ _*) => MergeStrategy.filterDistinctLines case PathList("META-INF", xs @ _*) => MergeStrategy.discard case "reference.conf" => MergeStrategy.concat case "application.conf" => MergeStrategy.concat case PathList("org", "apache", "spark", "unused", "UnusedStubClass.class") => MergeStrategy.first case _ => MergeStrategy.first } ``` 4. **排除某些依赖**: 如果某些依赖导致了难以解决的冲突,可以考虑排除它们。例如: ```scala libraryDependencies += "org.apache.spark" %% "spark-core" % sparkVersion % "provided" ``` 或者排除特定依赖中的某些包: ```scala libraryDependencies += "some.group" % "artifact" % "version" excludeAll( ExclusionRule(organization = "org.conflict") ) ``` 5. **使用`assemblyShadeRules`进行重定向(高级)**: 对于某些顽固的冲突,可以使用shade规则重命名包。例如: ```scala assemblyShadeRules in assembly := Seq( ShadeRule.rename("com.google.common.**" -> "shaded_guava.@1").inAll ) ``` 这样会将所有`com.google.common`包下的类重定向到`shaded_guava`包下,避免与其他库中的Guava冲突。 6. **解决多个主类的问题**: 除了在build.sbt中指定主类外,还可以在运行sbt assembly时指定: ```bash sbt "set mainClass in assembly := Some(\"com.example.Main\")" assembly ``` 7. **注意**:在Spark项目中,通常需要将`spark-core`和`spark-sql`设置为`provided`,避免打包到uber jar中,因为Spark集群已经提供了这些依赖。 示例build.sbt(部分): ```scala import sbtassembly.MergeStrategy name := "spark-app" version := "0.1" scalaVersion := "2.12.15" libraryDependencies += "org.apache.spark" %% "spark-core" % "3.3.0" % "provided" libraryDependencies += "org.apache.spark" %% "spark-sql" % "3.3.0" % "provided" // 指定主类 assembly / mainClass := Some("com.example.MainApp") // 自定义合并策略 assembly / assemblyMergeStrategy := { case PathList("META-INF", "services", xs @ _*) => MergeStrategy.filterDistinctLines case PathList("META-INF", xs @ _*) => MergeStrategy.discard case "reference.conf" => MergeStrategy.concat case "application.conf" => MergeStrategy.concat case PathList("org", "apache", "spark", "unused", "UnusedStubClass.class") => MergeStrategy.first case _ => MergeStrategy.first } ``` 8. **调试**: 如果仍然遇到冲突,可以运行以下命令查看详细冲突信息: ```bash sbt assembly ``` 当冲突发生时,sbt assembly会打印出冲突的文件和来源jar包。根据这些信息调整合并策略。 9. **清理缓存**: 有时候,sbt的缓存可能导致问题,可以尝试清理: ```bash sbt clean ``` 通过以上步骤,应该能够解决多个主类警告和重复类文件冲突的问题。 相关问题: 1. 如何为Spark应用配置sbt assembly的合并策略? 2. 在sbt中如何排除特定的传递依赖? 3. 如何解决Spark应用中的Guava版本冲突? 4. sbt assembly打包时如何指定主类?</think>### 解决 sbt assembly 时的多主类警告和重复类文件冲突问题 您遇到的两个核心问题: 1. `multiple main classes detected` 警告 2. `deduplicate: different file contents` 的重复类冲突 以下是系统化解决方案: --- ### 一、解决多主类警告 在 `build.sbt` 中添加主类指定: ```scala // 明确指定主类 mainClass in assembly := Some("com.yourpackage.MainApp") // 或自动选择第一个找到的主类 assembly / mainClass := Some( (Compile / discoveredMainClasses).value.headOption.getOrElse( throw new Exception("No main class found") ) ) ``` **说明**: - 使用 `sbt "show Compile/discoveredMainClasses"` 查看所有主类列表 - 推荐显式指定主类避免歧义[^1] --- ### 二、处理重复类冲突(核心方案) 在 `build.sbt` 中自定义合并策略: ```scala import sbtassembly.MergeStrategy assembly / assemblyMergeStrategy := { // 1. 优先处理常见冲突文件 case "module-info.class" => MergeStrategy.discard // Java 9+模块声明 case "META-INF/io.netty.versions.properties" => MergeStrategy.first case "META-INF/native-image/io.netty/**" => MergeStrategy.first // 2. 配置文件合并 case "reference.conf" => MergeStrategy.concat // Typesafe配置 case "application.conf" => MergeStrategy.concat // 3. 服务加载器文件合并 case PathList("META-INF", "services", xs @ _*) => MergeStrategy.filterDistinctLines // JDK ServiceLoader // 4. Spring特殊文件 case PathList("META-INF", "spring.handlers") => MergeStrategy.concat case PathList("META-INF", "spring.schemas") => MergeStrategy.concat // 5. 其他元数据丢弃 case PathList("META-INF", xs @ _*) => MergeStrategy.discard // 6. 默认策略:优先选择第一个出现的版本 case _ => MergeStrategy.first } ``` --- ### 三、Spark 专项优化 针对 Spark 依赖的特殊处理: ```scala libraryDependencies ++= Seq( "org.apache.spark" %% "spark-core" % sparkVersion % "provided", "org.apache.spark" %% "spark-sql" % sparkVersion % "provided", // 显式排除冲突库 ("com.typesafe.play" %% "play-json" % playJsonVersion) .exclude("com.google.guava", "guava") .exclude("org.slf4j", "slf4j-api") ) // Shading重定向解决顽固冲突 assemblyShadeRules := Seq( ShadeRule.rename("com.google.common.**" -> "shaded_guava.@1") .inLibrary("com.google.guava" % "guava" % "30.1.1-jre") .inProject ) ``` --- ### 四、验证与调试 1. **检查依赖树**: ```bash sbt dependencyTree > deps.txt ``` 搜索 `(c)` 标记的冲突依赖 2. **分析冲突文件**: ```bash sbt assembly ``` 当冲突出现时,sbt 会显示冲突文件的来源 JAR 包 3. **增量策略调试**: ```scala // build.sbt case "specific/conflict/Class.class" => MergeStrategy.rename // 重命名特定冲突类 // 或 MergeStrategy.pickFirst 强制选择第一个 ``` --- ### 五、完整配置示例 ```scala // build.sbt import sbtassembly.AssemblyPlugin.autoImport._ ThisBuild / version := "1.0" ThisBuild / scalaVersion := "2.12.15" lazy val root = (project in file(".")) .settings( name := "spark-app", mainClass in assembly := Some("com.example.MainApp"), assembly / assemblyJarName := "spark-app-uber.jar", assembly / assemblyMergeStrategy := { case PathList("META-INF", "services", xs @ _*) => MergeStrategy.filterDistinctLines case PathList("META-INF", xs @ _*) => MergeStrategy.discard case "reference.conf" => MergeStrategy.concat case "module-info.class" => MergeStrategy.discard case _ => MergeStrategy.first }, libraryDependencies ++= Seq( "org.apache.spark" %% "spark-core" % "3.3.0" % "provided", "org.apache.spark" %% "spark-sql" % "3.3.0" % "provided", "com.typesafe.play" %% "play-json" % "2.9.4" ) ) ``` --- ### 常见冲突解决方案表 | 冲突文件类型 | 推荐策略 | 适用场景 | |-------------|---------|---------| | `reference.conf` | `concat` | Typesafe配置 | | `module-info.class` | `discard` | Java 9+模块 | | `META-INF/services/*` | `filterDistinctLines` | 服务加载器 | | `spring.handlers` | `concat` | Spring框架 | | 版本冲突类文件 | `first` 或 `rename` | Guava/Netty等 | | 签名文件 | `discard` | 安全证书 | > **最佳实践**:优先使用`MergeStrategy.discard`处理元数据文件,对配置文件使用`concat`,核心类冲突使用`first`[^2]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值