gpt4 book ai didi

scala - 玩json库和sbt assembly合并报错

转载 作者:行者123 更新时间:2023-12-05 08:39:20 27 4
gpt4 key购买 nike

即使是一个简单的 Hello 程序,如果我在 build.sbt 文件中添加 play-json 作为库依赖项,当我在 sbt 中执行“assembly”命令时,我总是会遇到合并错误(sbt-assembly 插件).

[error] stack trace is suppressed; run last assembly for the full output
[error] (assembly) deduplicate: different file contents found in the following:
[error] /home/heitor/.cache/coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.10.1/jackson-annotations-2.10.1.jar:module-info.class
[error] /home/heitor/.cache/coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.10.1/jackson-core-2.10.1.jar:module-info.class
[error] /home/heitor/.cache/coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.10.1/jackson-databind-2.10.1.jar:module-info.class
[error] /home/heitor/.cache/coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/datatype/jackson-datatype-jdk8/2.10.1/jackson-datatype-jdk8-2.10.1.jar:module-info.class
[error] /home/heitor/.cache/coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.10.1/jackson-datatype-jsr310-2.10.1.jar:module-info.class

MergeApp.scala

object MergeApp extends App {
println("Hello")
}

构建.sbt

name := "MergeBug"

version := "0.1"

scalaVersion := "2.13.1"

val playJsonVersion = "2.8.1"

libraryDependencies ++= Seq("com.typesafe.play" %% "play-json" % playJsonVersion)

项目/build.properties

sbt.version = 1.3.8

项目/plugins.sbt

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10")

最佳答案

您需要定义自定义合并策略。参见 https://github.com/sbt/sbt-assembly#merge-strategy

由于 module-info.class 文件仅对 Java 9+ 模块有用,您可以安全地丢弃它们:

assemblyMergeStrategy in assembly := {
case "module-info.class" => MergeStrategy.discard
case x =>
val oldStrategy = (assemblyMergeStrategy in assembly).value
oldStrategy(x)
}

关于scala - 玩json库和sbt assembly合并报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60114651/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com