我有一个根项目,我想用sbt-assembly构建一个胖JAR。它有一个子项目,它依赖于我想为胖JAR忽略的根目录(就像它不存在一样)。我该怎么做呢?在构建胖项目的同时忽略子项目JAR的根项目
基本上我想根项目包好像有从build.sbt
没有localMode
子项目中尝试的1
尝试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
)
没有帮助。我在我的错误消息中添加了信息。 – Make42
@ Make42你也应该发布你的'build.sbt'。可能这个问题是可以解决的,只需正确配置你的子项目。 – laughedelic
你是否试图用项目范围调用它?像'root/assembly'。 – laughedelic