我正在尝试将构建定义从Scala转换为build.sbt
在Scala定义中,我有类似的东西:
lazy val ComponentTest = config("componenttest") extend Test
val componentTests = inConfig(ComponentTest)(Defaults.testTasks) ++ Seq(
testOptions in ComponentTest := Seq(Tests.Filter(componentTestFilter))
)
val main = play.Project(appName, appVersion, appDependencies ++ testDependencies)
.settings(...)
.configs(ComponentTest)
.settings(componentTests: _*)
private def componentTestFilter(name: String): Boolean = name endsWith "CT"
我还没有找到如何将Project.configs(ComponentTest)迁移到build.sbt
我找到的唯一解决方案要复杂得多:
lazy val ComponentTest = config("componenttest") extend Test
inConfig(ComponentTest)(Defaults.testSettings)
javaSource in ComponentTest := (javaSource in Test).value
scalaSource in ComponentTest := (scalaSource in Test).value
configuration in ComponentTest := (configuration in Test).value
testOptions in ComponentTest := (testOptions in Test).value
testOptions in Test += Tests.Filter(unitFilter)
testOptions in ComponentTest := Seq(Tests.Filter(componentTestFilter))
def componentTestFilter(name: String): Boolean = name endsWith "CT"
再次定义所有设置(javaSource,scalaSource ...)感觉不对。
还有更好的东西吗? 或者我应该混合.scala和.sbt定义? 还是坚持.scala?
答案 0 :(得分:3)
您可以使用project
宏来参考您的项目。
lazy val main = project.in(file(".")).configs(ComponentTest)
lazy val ComponentTest = config("componenttest") extend Test
inConfig(ComponentTest)(Defaults.testTasks) ++ Seq(
testOptions in ComponentTest := Seq(Tests.Filter(componentTestFilter))
)
def componentTestFilter(name: String): Boolean = name endsWith "CT"
至于你的问题,你是否应该混合使用.scala
和.sbt
。我认为这在需要时是一种有效的方法。 build.sbt
有limitations,例如不共享不同.sbt
文件中的代码,编写复杂的构建很不方便(您必须记住在每个语句后添加额外的行并将所有表达式保持在一起)。
我会说你应该坚持适合你的任何事情。