2016-10-21 185 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 
} 
相關問題