2016-10-21 148 views
0

我无法将测试依赖关系打包到我的测试程序集jar中。下面是我的build.sbt的摘录:如何在sbt-assembly jar中包含测试依赖关系?

... 

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(即"com.typesafe.play" %% "play-json" % "2.3.10" excludeAll ExclusionRule(organization = "joda-time"))中删除"test"配置,我可以看到它包含在内:

$ jar tf /path/to/project-test.jar | grep play 
... 
play/libs/Json.class 
... 
$ 

我是否做错了什么和/或错过了什么?在这里,我的目标是包括仅在test:assembly罐子play-json库,而不是assembly罐子

回答

0

我已经在原来的build.sbt摘录我张贴上面这竟然是issuse的原因离开了关键部分:

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 
} 

该代码块本质上是从测试类路径中筛选出来的。我们将其纳入以避免痛苦的合并冲突。我通过添加逻辑来解决这个问题,包括需要的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 
} 
相关问题