使用`resourceGenerators`创建文件

时间:2016-12-23 14:17:19

标签: scala sbt

假设:

$cat build.sbt
scalaVersion := "2.12.1"

resourceGenerators in Compile += Def.task {
  val file = (resourceManaged in Compile).value / "demo" / "myapp.properties"
  val contents = "name=%s\nversion=%s".format(name.value,version.value)
  IO.write(file, contents)
  Seq(file)
}.taskValue

$sbt compile
[info] Set current project to sbt_testing (in build file:/home/kmeredith/src/sbt_testing/)
[info] Updating {file:/home/kmeredith/src/sbt_testing/}sbt_testing...
[info] Resolving jline#jline;2.14.1 ...
[info] Done updating.
[success] Total time: 1 s, completed Dec 23, 2016 9:14:50 AM

我的理解是应该在myapp.properties任务期间创建compile文件。

但是,我看到没有创建这样的文件:

$find . -name *.properties
./target/resolution-cache/default/sbt_testing_2.12/0.1-SNAPSHOT/resolved.xml.properties

请向我解释如何生成myapp.properties

1 个答案:

答案 0 :(得分:2)

您对触发资源生成有错误的期望 - 运行compile不会触发它(编译现有的源但不生成生成的源!),但是如果执行test或{{1它将被生成:

run