【发布时间】:2016-11-30 01:31:36
【问题描述】:
我有一个根项目,我想用 sbt-assembly 构建一个胖 JAR。它确实有一个子项目,它取决于我想要忽略胖 JAR 的根(好像它不存在一样)。我该怎么做?
基本上我想要根项目包,就好像 Try 1 中的 build.sbt 没有 localMode 子项目一样。
试试 1
我的build.sbt 是
import sbt.Keys._
name := "myprojectname"
version := "0.0.1-SNAPSHOT"
scalaVersion in ThisBuild := "2.11.8"
mainClass in(Compile, run) := Some("com.mywebsite.MyExample")
mainClass in(Compile, packageBin) := Some("com.mywebsite.MyExample")
mainClass in assembly := Some("com.mywebsite.MyExample")
libraryDependencies += "org.apache.spark" %% "spark-core" % "2.0.0" % Provided
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.0" % Test
lazy val localMode = project.
in(file("localMode")).
dependsOn(RootProject(file("."))).
settings(
name := "myprojectname_local",
libraryDependencies += "org.apache.spark" %% "spark-core" % "2.0.0" % Compile,
mainClass in(Compile, run) := Some("com.mywebsite.MyExample"),
mainClass in(Compile, packageBin) := Some("com.mywebsite.MyExample")
)
fullClasspath in assembly := {
(fullClasspath in assembly).value diff
(fullClasspath in assembly in localMode).value
}
目前我收到错误消息:
[error] (localMode/*:assembly) deduplicate: different file contents found in the following:
[error] ~/.ivy2/cache/org.sonatype.sisu/sisu-guice/jars/sisu-guice-2.1.7-noaop.jar:com/google/inject/AbstractModule.class
[error] ~/.ivy2/cache/com.google.inject/guice/jars/guice-3.0.jar:com/google/inject/AbstractModule.class
[error] deduplicate: different file contents found in the following:
[error] ~/.ivy2/cache/org.sonatype.sisu/sisu-guice/jars/sisu-guice-2.1.7-noaop.jar:com/google/inject/Binder.class
[error] ~/.ivy2/cache/com.google.inject/guice/jars/guice-3.0.jar:com/google/inject/Binder.class
[error] deduplicate: different file contents found in the following:
[error] ~/.ivy2/cache/org.sonatype.sisu/sisu-guice/jars/sisu-guice-2.1.7-noaop.jar:com/google/inject/ConfigurationException.class
[error] ~/.ivy2/cache/com.google.inject/guice/jars/guice-3.0.jar:com/google/inject/ConfigurationException.class
and so on...
如果我命令sbt root/assembly 我得到
[error] Expected ID character
[error] Not a valid command: root (similar: reboot, boot, project)
[error] Expected project ID
[error] Expected configuration
[error] Expected ':' (if selecting a configuration)
[error] Expected key
[error] Not a valid key: root (similar: products)
[error] root/assembly
[error] ^
试试 2
我的第二个build.sbt 无法构建:
import sbt.Keys._
lazy val commonSettings = Seq(
version := "0.0.1-SNAPSHOT",
scalaVersion in ThisBuild := "2.11.8",
mainClass in(Compile, run) := Some("com.mywebsite.MyExample"),
mainClass in(Compile, packageBin) := Some("com.mywebsite.MyExample"),
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.0" % Test
)
lazy val root = project.
in(file("root")).
dependsOn(RootProject(file("."))).
settings(
name := "myprojectname",
libraryDependencies += "org.apache.spark" %% "spark-core" % "2.0.0" % Provided,
mainClass in assembly := Some("com.mywebsite.MyExample")
)
lazy val localMode = project.
in(file("localMode")).
dependsOn(RootProject(file("."))).
settings(
name := "myprojectname_local",
libraryDependencies += "org.apache.spark" %% "spark-core" % "2.0.0" % Compile
)
【问题讨论】:
标签: sbt sbt-assembly