用sbt替换文本文件中的变量

用sbt替换文本文件中的变量,sbt,Sbt,我有遗留的SBT构建文件。作为构建过程的一部分,我需要替换文本文件中的一个特定字符串。 特别是在public/index.html文件中的Play框架应用程序中,我需要将占位符字符串替换为GA UUID代码 您可以编写一个自定义资源生成器,用于读取文件、替换占位符并将其写入文件 resourceGenerators in Compile += Def.task { val content = IO.read(resourceDirectory.value / "index.html")

我有遗留的SBT构建文件。作为构建过程的一部分,我需要替换文本文件中的一个特定字符串。
特别是在public/index.html文件中的Play框架应用程序中,我需要将占位符字符串替换为GA UUID代码

您可以编写一个自定义资源生成器,用于读取文件、替换占位符并将其写入文件

resourceGenerators in Compile += Def.task {
  val content = IO.read(resourceDirectory.value / "index.html")
  val out = (resourceManaged in Compile).value / "index.html"
  IO.write(out, content.replace("<build-time>", System.currentTimeMillis.toString))
  Seq(out)
}

您可以编写一个自定义资源生成器,用于读取文件、替换占位符并将其写入文件

resourceGenerators in Compile += Def.task {
  val content = IO.read(resourceDirectory.value / "index.html")
  val out = (resourceManaged in Compile).value / "index.html"
  IO.write(out, content.replace("<build-time>", System.currentTimeMillis.toString))
  Seq(out)
}

实际上,Aki提供的经确认的解决方案中缺少一个额外的in-Compile:

resourceGenerators in Compile += Def.task {
  val content = IO.read((resourceDirectory in Compile).value / "index.html")
  val out = (resourceManaged in Compile).value / "index.html"
  IO.write(out, content.replace("<build-time>", System.currentTimeMillis.toString))
  Seq(out)
}

我本想添加一条评论,但我没有足够的声誉:

实际上,Aki提供的经确认的解决方案中缺少一个额外的in-Compile:

resourceGenerators in Compile += Def.task {
  val content = IO.read((resourceDirectory in Compile).value / "index.html")
  val out = (resourceManaged in Compile).value / "index.html"
  IO.write(out, content.replace("<build-time>", System.currentTimeMillis.toString))
  Seq(out)
}
我本想添加一条评论,但我没有足够的声誉: