【问题标题】:How to create sources from resources (or other project files) in SBT如何在 SBT 中从资源(或其他项目文件)创建源
【发布时间】:2017-02-11 22:02:44
【问题描述】:

我想从作为项目一部分的文件生成源(我目前已将它们放在资源目录中,但这不是必需的)。

这是我的尝试:

sourceGenerators in Test += (sourceManaged in Test map { src =>
  (unmanagedResourceDirectories in Test).value map { dir =>
    val file = dir / "demo" / src.name
    IO.write(file, "Prefix---" + IO.read(src) + "---Postfix")
    file
  }
}).taskValue

这给了我一个错误:

错误:非法的动态依赖 (测试中的 unmanagedResourceDirectories).value map { src =>

这样做的正确方法是什么?

【问题讨论】:

    标签: scala sbt


    【解决方案1】:

    最终起作用的是这个(灵感来自this code,在对问题SBT sourceGenerators task - execute only if a file changes的评论中引用):

    sourceGenerators in Test += Def.task {
      val sources = (unmanagedResources in Test).value filter ( _.isFile )
      val dir = (sourceManaged in Test).value
      sources map { src =>
        IO.write(dir / src.name, "Prefix---" + IO.read(src) + "---Postfix")
        f
      }
    }.taskValue
    

    重要的部分是读取任务内部的设置。

    【讨论】:

      【解决方案2】:

      【讨论】:

      • 我希望你是对的,但你能举一个更具体的例子吗?到目前为止,我对它们的实验并不成功。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-04
      • 2016-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-13
      相关资源
      最近更新 更多