[英]How to include test dependencies in sbt-assembly jar?
我無法將測試依賴項打包在測試程序罐中。 這是我的build.sbt
的摘錄:
...
name := "project"
scalaVersion := "2.10.6"
assemblyOption in (Compile, assembly) := (assemblyOption in (Compile, assembly)).value.copy(includeScala = false)
fork in Test := true
parallelExecution in IntegrationTest := false
lazy val root = project.in(file(".")).configs(IntegrationTest.extend(Test)).settings(Defaults.itSettings: _ *)
Project.inConfig(Test)(baseAssemblySettings)
test in (Test, assembly) := {}
assemblyOption in (Test, assembly) := (assemblyOption in (Test, assembly)).value.copy(includeScala = false, includeDependency = true)
assemblyJarName in (Test, assembly) := s"${name.value}-test.jar"
fullClasspath in (Test, assembly) := {
val cp = (fullClasspath in Test).value
cp.filter{ file => (file.data.name contains "classes") || (file.data.name contains "test-classes")} ++ (fullClasspath in Runtime).value
}
libraryDependencies ++= Seq(
...
"com.typesafe.play" %% "play-json" % "2.3.10" % "test" excludeAll ExclusionRule(organization = "joda-time"),
...
)
...
當我使用sbt test:assembly
組裝胖子罐子時,會產生胖子罐子project-test.jar
,但是play-json
依賴項沒有打包在其中:
$ jar tf /path/to/project-test.jar | grep play
$
但是,如果我從play-json
dep中刪除了"test"
配置(即"com.typesafe.play" %% "play-json" % "2.3.10" excludeAll ExclusionRule(organization = "joda-time")
)) ,我可以看到它包含在其中:
$ jar tf /path/to/project-test.jar | grep play
...
play/libs/Json.class
...
$
我在做錯什么和/或錯過任何事情嗎? 我的目標是將play-json
庫僅包含在test:assembly
jar中,而不包括assembly
jar中
我在上面發布的原始build.sbt
摘錄中遺漏了關鍵部分,事實證明這是build.sbt
的原因:
fullClasspath in (Test, assembly) := {
val cp = (fullClasspath in Test).value
cp.filter{ file => (file.data.name contains "classes") || (file.data.name contains "test-classes")} ++ (fullClasspath in Runtime).value
}
該代碼塊實際上是從測試類路徑中過濾掉dep的。 我們將其包括在內以避免痛苦的合並沖突。 我通過添加邏輯以包含所需的play-json
dep來解決此問題:
fullClasspath in (Test, assembly) := {
val cp = (fullClasspath in Test).value
cp.filter{ file =>
(file.data.name contains "classes") ||
(file.data.name contains "test-classes") ||
// sorta hacky
(file.data.name contains "play")
} ++ (fullClasspath in Runtime).value
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.