使用 sbt-assembly 的程序集合并策略问题 [英] assembly-merge-strategy issues using sbt-assembly

查看:31
本文介绍了使用 sbt-assembly 的程序集合并策略问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 sbt-assembly 将 scala 项目转换为可部署的 fat jar.当我在 sbt 中运行我的组装任务时,我收到以下错误:

I am trying to convert a scala project into a deployable fat jar using sbt-assembly. When I run my assembly task in sbt I am getting the following error:

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 文档:

Now from the sbt-assembly documentation:

如果多个文件共享相同的相对路径(例如,一个名为application.conf 在多个依赖 JAR 中),默认策略是验证所有候选人具有相同的内容和错误否则.可以使用基于每个路径配置此行为以下内置策略之一或编写自定义策略:

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 是上面描述的默认值
  • MergeStrategy.first 按类路径顺序选择第一个匹配的文件
  • MergeStrategy.last 选择最后一个
  • MergeStrategy.singleOrError 以冲突错误消息退出
  • MergeStrategy.concat 简单地连接所有匹配的文件并包含结果
  • MergeStrategy.filterDistinctLines 也连接,但沿途省略重复项
  • MergeStrategy.rename 重命名源自 jar 文件的文件
  • MergeStrategy.discard 只是丢弃匹配的文件
  • 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 设置如下:

Going by this I setup my build.sbt as follows:

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 的最后一行,我有:

In the last line of the build.sbt, I have:

mergeStrategy in assembly := mergeStrategy.first

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

Now, when I run SBT, I get the following error:

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

有人能指出我在这里做错了什么吗?

Can somebody point out what I might be doing wrong here?

谢谢

推荐答案

我觉得应该是MergeStrategy.first加大写M,所以mergeStrategy in组装 := MergeStrategy.first.

I think it should be MergeStrategy.first with a capital M, so mergeStrategy in assembly := MergeStrategy.first.

这篇关于使用 sbt-assembly 的程序集合并策略问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆