繁体   English   中英

如何在sbt-assembly jar中包括测试依赖项?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM