我们刚刚升级到在我们的项目中使用sbt 12.2。我想将我们的测试打包在单独的jar中,例如:project-unit.jar,project-integration.jar
我们当前的文件夹结构是:
src
main
...
test
scala
com.company.unit
com.company.integration
com.company.functional
非常感谢任何建议。
由于
答案 0 :(得分:1)
我找到了一种方法:
为相应的测试类型创建打包任务:
val integrationPackaging = TaskKey[File]("package-integration")
将包设置添加到测试设置:
lazy val integrationTestSettings = createTestSettings("integration", IntegrationTests) ++ createPackageSettings("integration", IntegrationTests, integrationPackaging)
private def createPackageSettings(testType: String, testConfiguration: Configuration, packagingTaskKey: TaskKey[sbt.File]) = {
inConfig(testConfiguration)(Defaults.testSettings) ++
Defaults.packageTaskSettings(packagingTaskKey, mappings in (Test, packageBin)) ++
(artifactName in packagingTaskKey := {(scalaversion, moduleId, artifact) => "%s_%s-%s-%s.jar" format (moduleId.name, scalaversion.binary, buildVersion, testType)}) ++
(mappings in packagingTaskKey ~= { (ms: Seq[(File,String)]) =>
ms.filter { case (file, path) =>{ !file.getName.endsWith(".class") || file.getAbsolutePath.contains(testType) }
}
})
}
请注意,在创建包设置中,我必须: