加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – 使用sbt-assembly的assembly-merge-strategy问题

发布时间:2020-12-16 09:39:18 所属栏目:安全 来源:网络整理
导读:我正在尝试使用 sbt-assembly将Scala项目转换为可部署的胖罐。当我在sbt中运行我的程序集任务时,我收到以下错误: Merging 'org/apache/commons/logging/impl/SimpleLog.class' with strategy 'deduplicate' :assembly: deduplicate: different file conten
我正在尝试使用 sbt-assembly将Scala项目转换为可部署的胖罐。当我在sbt中运行我的程序集任务时,我收到以下错误:

Merging 'org/apache/commons/logging/impl/SimpleLog.class' with strategy 'deduplicate'
    :assembly: deduplicate: different file contents found in the following:
    [error] /Users/home/.ivy2/cache/commons-logging/commons-logging/jars/commons-logging-1.1.1.jar:org/apache/commons/logging/impl/SimpleLog.class
    [error] /Users/home/.ivy2/cache/org.slf4j/jcl-over-slf4j/jars/jcl-over-slf4j-1.6.4.jar:org/apache/commons/logging/impl/SimpleLog.class

现在从sbt-assembly文档:

If multiple files share the same relative path (e.g. a resource named
application.conf in multiple dependency JARs),the default strategy is
to verify that all candidates have the same contents and error out
otherwise. This behavior can be configured on a per-path basis using
either one of the following built-in strategies or writing a custom one:

  • MergeStrategy.deduplicate is the default described above
  • MergeStrategy.first picks the first of the matching files in classpath order
  • MergeStrategy.last picks the last one
  • MergeStrategy.singleOrError bails out with an error message on conflict
  • MergeStrategy.concat simply concatenates all matching files and includes the result
  • MergeStrategy.filterDistinctLines also concatenates,but leaves out duplicates along the way
  • MergeStrategy.rename renames the files originating from jar files
  • MergeStrategy.discard simply discards matching files

通过这个我设置我的build.sbt如下:

import sbt._
import Keys._
import sbtassembly.Plugin._
import AssemblyKeys._
name := "my-project"
version := "0.1"
scalaVersion := "2.9.2"
crossScalaVersions := Seq("2.9.1","2.9.2")

//assemblySettings
seq(assemblySettings: _*)

resolvers ++= Seq(
    "Typesafe Releases Repository" at "http://repo.typesafe.com/typesafe/releases/","Typesafe Snapshots Repository" at "http://repo.typesafe.com/typesafe/snapshots/","Sonatype Repository" at "http://oss.sonatype.org/content/repositories/releases/"
)

libraryDependencies ++= Seq(
    "org.scalatest" %% "scalatest" % "1.6.1" % "test","org.clapper" %% "grizzled-slf4j" % "0.6.10","org.scalaz" % "scalaz-core_2.9.2" % "7.0.0-M7","net.databinder.dispatch" %% "dispatch-core" % "0.9.5"
)

scalacOptions += "-deprecation"
mainClass in assembly := Some("com.my.main.class")
test in assembly := {}
mergeStrategy in assembly := mergeStrategy.first

在build.sbt的最后一行,我有:

mergeStrategy in assembly := mergeStrategy.first

现在,当我运行SBT,我得到以下错误:

error: value first is not a member of sbt.SettingKey[String => sbtassembly.Plugin.MergeStrategy]
    mergeStrategy in assembly := mergeStrategy.first

有人可以指出我在这里做错什么?

谢谢

解决方法

我认为它应该是MergeStrategy.first与资本M,所以mergeStrategy在汇编:= MergeStrategy.first。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读