我们刚刚升级到在我们的项目中使用 sbt 12.2。我想将我们的测试打包在单独的 jar 中,例如:project-unit.jar、project-integration.jar
我们当前的文件夹结构是:
src
main
...
test
scala
com.company.unit
com.company.integration
com.company.functional
任何建议都非常感谢。
谢谢
我找到了一种方法来做到这一点:
为适当的测试类型创建打包任务:
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) }
}
})
}
注意在创建包设置中,我必须: