scala SBT 程序集不起作用(不是有效的命令)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36186214/
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
SBT Assembly not working (not a valid command)
提问by lbollar
I have tried a lot of solutions that I could find related to this topic. Above all of them,
我已经尝试了很多可以找到与此主题相关的解决方案。最重要的是,
sbt assembly command not found
looked the most related, but that did not solve it.
看起来最相关,但这并没有解决它。
I am using sbt 13.7
我正在使用 sbt 13.7
build.sbt:
构建.sbt:
lazy val commonSettings = Seq(
organization := "com.example",
version := "0.1.0"
)
lazy val app = (project in file(".")).
settings(commonSettings: _*).
settings(
name := "fat-jar-test"
)
assembly.sbt:
程序集.sbt:
resolvers += Resolver.url("bintray-sbt-plugins", url("http://dl.bintray.com/sbt/sbt-plugin-releases"))(Resolver.ivyStylePatterns)
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2")
project structure
项目结构
root
|
src
target
project
|
build.sbt
assembly.sbt
In sbt I compile succesfully, I can package succesfully, but when I run assembly command I get:
在 sbt 中我编译成功,我可以成功打包,但是当我运行汇编命令时,我得到:
[error] Not a valid command: assembly
[error] Not a valid project ID: assembly
[error] Expected ':' (if selecting a configuration)
[error] Not a valid key: assembly
[error] assembly
[error]
I am using Intellij but running sbt from terminal.
I am on Mac OSX.
I originally downloaded sbt and installed from their site, normal installation. I removed and tried installing from macports, no difference.
I had scala version in build.sbt setting, but removed it because I was getting errors and read the 2.11.x does not work with sbt. That stopped errors, but I still have assembly problem.
我正在使用 Intellij 但从终端运行 sbt。
我在 Mac OSX 上。
我最初是从他们的网站下载sbt并安装的,正常安装。我删除并尝试从 macports 安装,没有区别。
我在 build.sbt 设置中有 Scala 版本,但删除了它,因为我收到错误并读取 2.11.x 不适用于 sbt。这停止了错误,但我仍然有组装问题。
EDIT:
编辑:
I was unsure of placement of build.sbt in this structure. Before I had it in the root directory. At suggest of Roman below, I have moved it back to there, but alas I receive the exact same error.
我不确定 build.sbt 在这个结构中的位置。在我把它放在根目录之前。根据下面的 Roman 的建议,我已将其移回那里,但可惜我收到了完全相同的错误。
回答by Roman
Pull 1 level up your build.sbt. It should reside in project root, not it project.
将您的build.sbt. 它应该驻留在项目根目录中,而不是 it project。
Also it's possible to have build.sbtin projectfolder as well, it means a different thing. Read Organizing Builddocument for some insight.
也可以build.sbt在project文件夹中,这意味着不同的事情。阅读组织构建文档以获得一些见解。
UPD: as @marios has suggested, can you also put resolvers to your build.sbt. Also, it's important to set SNAPSHOT version for your build. The whole content of your build.sbtshould be the following:
UPD:正如@marios 所建议的那样,您是否也可以将解析器放入 build.sbt。此外,为您的构建设置 SNAPSHOT 版本也很重要。你的全部内容build.sbt应该如下:
scalaVersion in ThisBuild := "2.11.7"
lazy val commonSettings = Seq(
organization := "com.example",
version := "0.1.0-SNAPSHOT"
)
lazy val app = (project in file(".")).
settings(commonSettings: _*).
settings(
name := "fat-jar-test"
).
enablePlugins(AssemblyPlugin)
resolvers in Global ++= Seq(
"Sbt plugins" at "https://dl.bintray.com/sbt/sbt-plugin-releases",
"Maven Central Server" at "http://repo1.maven.org/maven2",
"TypeSafe Repository Releases" at "http://repo.typesafe.com/typesafe/releases/",
"TypeSafe Repository Snapshots" at "http://repo.typesafe.com/typesafe/snapshots/"
)
Then, add two more files to root/projectfolder:
然后,将另外两个文件添加到root/project文件夹:
root/project/build.propertiescontains a single line:
root/project/build.properties包含一行:
sbt.version=0.13.7
root/project/plugins.sbtalso contains a single line:
root/project/plugins.sbt还包含一行:
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.12.0")
Now, remove your root/project/assembly.sbtfile (although it's fine to have it instead of plugins.sbt, but let's just try - this configuration always works for me).
现在,删除您的root/project/assembly.sbt文件(虽然可以使用它代替plugins.sbt,但让我们尝试一下 - 这种配置总是对我有用)。
Now, your project layout should be the following:
现在,您的项目布局应如下所示:
root
|
build.sbt
src
project
|
plugins.sbt
build.properties
Reload sbt and try pluginscommand. You should see sbtassembly.AssemblyPluginthere.
重新加载 sbt 并尝试plugins命令。你应该去sbtassembly.AssemblyPlugin那里看看。
回答by Jeberdson Abraham
Even after trying the above solution if the problem exists, them Try Restarting your MachineIt solved the problem for me after breaking my head for a whole day.
即使在尝试上述解决方案后,如果问题存在,他们尝试重新启动您的机器它在我头破了一天之后为我解决了问题。

