scala 使 sbt-assembly 工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10988112/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 04:14:29  来源:igfitidea点击:

Getting sbt-assembly working

scalajarsbttypesafe-stacksbt-assembly

提问by adelbertc

So thus far I've been compiling my Scala project with SBT (via Typesafe stack). I want to run the code across several machines now, via sbt-assembly. Following directions, the only one change I made was in my project/Build.scalafile. Here is the related part:

到目前为止,我一直在用 SBT(通过类型安全堆栈)编译我的 Scala 项目。我现在想通过sbt-assembly在多台机器上运行代码。按照指示,我所做的唯一更改是在我的project/Build.scala文件中。这是相关的部分:

resolvers += "Typesafe Releases" at "http://repo.typesafe.com/typesafe/releases",
resolvers += "artifactory" at "http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases",
libraryDependencies += "com.eed3si9n" % "sbt-assembly" % "0.8.3"

When I run sbt compilehowever, I get this error:

sbt compile但是,当我运行时,出现此错误:

sbt.ResolveException: unresolved dependency: com.eed3si9n#sbt-assembly/scala_2.9.1/sbt_0.11.2;0.8.3: not found.

sbt.ResolveException: unresolved dependency: com.eed3si9n#sbt-assembly/scala_2.9.1/sbt_0.11.2;0.8.3: not found.

What am I doing wrong?

我究竟做错了什么?

Thanks!

谢谢!

EDITCreated a build.sbtfile in the same folder as Build.scala(folder is /project/) and have these two lines in it:

编辑build.sbt在与Build.scala(文件夹是/project/)相同的文件夹中 创建了一个文件,并在其中包含以下两行:

Seq[Setting[_]](resolvers += "artifactory" at "http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases",
                addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.8.3"))

Now the error is:

现在的错误是:

[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: com.eed3si9n#sbt-assembly;0.8.3: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn] 
[warn]  Note: Some unresolved dependencies have extra attributes.  Check that these dependencies exist with the requested attributes.
[warn]      com.eed3si9n:sbt-assembly:0.8.3 (sbtVersion=0.11.2, scalaVersion=2.9.1)
[warn] 
[error] {file:/Users/myname/current/projectname/project/}default-d7da9a/*:update: sbt.ResolveException: unresolved dependency: com.eed3si9n#sbt-assembly;0.8.3: not found

EDIT 2Hm, after I do a successful sbt compile, should I just be able to enter the sbtconsole and type in assembly?

编辑 2嗯,在我成功之后,我是否sbt compile应该能够进入sbt控制台并输入assembly

> assembly
[error] Not a valid command: assembly
[error] Not a valid project ID: assembly
[error] Not a valid configuration: assembly
[error] Not a valid key: assembly
[error] assembly
[error]   

EDIT 3JK got it. Had to add the build.sbtinfo as specified in the GitHub README.

编辑 3JK 明白了。必须添加build.sbtGitHub README 中指定的信息。

采纳答案by RM.

There are two points here. One is that SBT plugins are not justlibrary dependencies -- in particular, they use the current SBT version in a similar way that other Scala libraries use the Scala version. The other is that libraryDependenciesin project/Build.scalaaffects the dependencies for the project, not for the build.

这里有两点。一个是 SBT 插件不仅仅是库依赖——特别是,它们使用当前 SBT 版本的方式与其他 Scala 库使用 Scala 版本的方式类似。另一个是libraryDependenciesinproject/Build.scala影响项目的依赖关系,而不是构建

An SBT full build is itself an SBT project, just located one level down the directory tree, and so can have a build of its own configured the same way a normal build is. Unlike a normal build, where going for a "full build" is necessary under a handful of circumstances, there is almost never a reason to use a full build for a build, so using .sbtfiles located in project/is almost always sufficient.

SBT 完整构建本身就是一个 SBT 项目,仅位于目录树的下一级,因此可以像普通构建一样配置自己的构建。与在少数情况下需要进行“完整构建”的普通构建不同,几乎没有理由为构建使用完整构建,因此使用.sbt位于 中的文件project/几乎总是足够的。

The other issue is the versioning. SBT has a utility function called addSbtPluginthat handles everything for you. It takes a moduleID and adds all the necessary SBT and Scala versioning information.

另一个问题是版本控制。SBT 有一个名为的实用函数addSbtPlugin,可以为您处理所有事情。它需要一个 moduleID 并添加所有必要的 SBT 和 Scala 版本信息。

So, to get sbt-assembly working in a full build, you create a .sbtfile in under project/(conventionally either project/build.sbtor project/plugins.sbt) and place your build's resolvers and dependencies there:

因此,要让 sbt-assembly 在完整构建中工作,您需要.sbtproject/(通常为project/build.sbtproject/plugins.sbt)下创建一个文件,并将构建的解析器和依赖项放在那里:

resolvers += Resolver.url("artifactory", url("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases"))(Resolver.ivyStylePatterns)

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