我在sbt中有一个项目w / subprojects。我构建并对每个子项目进行单元测试。我希望有一个独特的子项目“集成”,我将进行集成测试。在运行这些测试之前,我想强制为每个子项目构建一个Docker镜像。
仅使用一个子项目作为示例我尝试了这个:
lazy val msg = project.in(file("msg"))
.settings(basicSettings: _*)
.settings(dockerStuff:_*)
.settings(libraryDependencies ++=
dep_compile(microcore, akka_cluster, akka_cluster_tools, opencmis, apns, handlebars) ++
dep_test(scalatest)
)
lazy val integration = project.in(file("integration"))
.settings(basicSettings: _*)
.settings(libraryDependencies ++=
dep_test(microcore, scalatest)
)
.dependsOn(msg % "publishLocal in Docker")
这产生了这个错误:
[trace] Stack trace suppressed: run last integration/*:clean for the full output.
[error] (integration/*:clean) java.lang.IllegalArgumentException: Cannot add dependency 'com.cof#msg_2.11;0.1_SNAPSHOT' to configuration 'publishLocal in Docker' of module com.cof#integration_2.11;9c2539_SNAPSHOT because this configuration doesn't exist!
[error] Total time: 0 s, completed Feb 16, 2016 3:35:18 PM
我错过了什么?这是我的集成子项目触发/强制在msg子项目上构建Docker的正确方法吗?
答案 0 :(得分:0)
这对我有用:创建一个在msg中定义的构建Docker镜像的任务。然后将该任务连接到testOnly(或测试或其他)集成中。为了实现这一目标,我们采取了一些烦躁不安的行动,但这似乎有效。
lazy val buildDocker = taskKey[Unit]("Build Dockers")
lazy val msg = project.in(file("msg"))
.settings(basicSettings: _*)
.settings(dockerStuff:_*)
.settings(
buildDocker in ThisBuild := (publishLocal in Docker).value // ThisBuild exposes dockz to the entire build
)
.settings(libraryDependencies ++=
dep_compile(microcore, akka_cluster, akka_cluster_tools, opencmis, apns, handlebars) ++
dep_test(scalatest)
)
lazy val integration = project.in(file("integration"))
.settings(basicSettings: _*)
.settings(libraryDependencies ++=
dep_test(microcore, scalatest)
)
.settings((Keys.testOnly in Test) <<= (Keys.testOnly in Test) dependsOn (buildDocker)) // wire testOnly to buildDocker