从项目列表创建动态设置

时间:2016-11-17 13:23:56

标签: scala sbt

我正在尝试在多项目SBT构建中创建一个设置,该构建是从Project列表中动态生成的。

我有一个名为riffRaffArtifactResources的{​​{1}}类型的任务键,我想创建一个签名为TaskKey[Seq[(File, String)]]的函数,并根据列表返回所需的设置提供的项目。

我可以手动设置 - 这样的东西可行,但是很长且容易出错:

Seq[Project] => Seq[Setting[_]]

我的初步(简化)尝试是:

riffRaffArtifactResources := Seq(
      (riffRaffPackageType in admin).value -> s"${(name in admin).value}/${(riffRaffPackageType in admin).value.getName}",
      (riffRaffPackageType in adminJobs).value -> s"${(name in adminJobs).value}/${(riffRaffPackageType in adminJobs).value.getName}",
      (riffRaffPackageType in applications).value -> s"${(name in applications).value}/${(riffRaffPackageType in applications).value.getName}",
      (riffRaffPackageType in archive).value -> s"${(name in archive).value}/${(riffRaffPackageType in archive).value.getName}",
      (riffRaffPackageType in article).value -> s"${(name in article).value}/${(riffRaffPackageType in article).value.getName}",
      (riffRaffPackageType in commercial).value -> s"${(name in commercial).value}/${(riffRaffPackageType in commercial).value.getName}",
      (riffRaffPackageType in diagnostics).value -> s"${(name in diagnostics).value}/${(riffRaffPackageType in diagnostics).value.getName}",
      (riffRaffPackageType in discussion).value -> s"${(name in discussion).value}/${(riffRaffPackageType in discussion).value.getName}",
      (riffRaffPackageType in identity).value -> s"${(name in identity).value}/${(riffRaffPackageType in identity).value.getName}",
      (riffRaffPackageType in facia).value -> s"${(name in facia).value}/${(riffRaffPackageType in facia).value.getName}",
      (riffRaffPackageType in faciaPress).value -> s"${(name in faciaPress).value}/${(riffRaffPackageType in faciaPress).value.getName}",
      (riffRaffPackageType in onward).value -> s"${(name in onward).value}/${(riffRaffPackageType in onward).value.getName}",
      (riffRaffPackageType in rss).value -> s"${(name in rss).value}/${(riffRaffPackageType in rss).value.getName}",
      (riffRaffPackageType in sport).value -> s"${(name in sport).value}/${(riffRaffPackageType in sport).value.getName}",
      baseDirectory.value / "riff-raff.yaml" -> "riff-raff.yaml"
    )

可悲的是,这给了我一个错误:def uniArtifactSimple(projects: Project*): Seq[Setting[_]] = Seq( riffRaffArtifactResources := projects.toSeq.map { project => val artifactFile = (riffRaffPackageType in project).value val projectName = (name in project).value artifactFile -> s"$projectName/${artifactFile.getName}" } ) (实际上是两个,每个参考一个)。

经过相当多的摆弄后,我使用Illegal dynamic reference: project完成了一些事情,但仍然无法进行编译。我的最新尝试是:

taskDyn

虽然我的类型对齐但我显然不明白宏如何正常工作以正确地构造它。

我在搜索中找到的最接近的示例是https://github.com/scalacenter/scalajs-bundler/blob/14b77c18292a9bcb05e9a204fc72adf1a75b0bf4/sbt-web-scalajs-bundler/src/main/scala/scalajsbundler/WebScalaJSBundlerPlugin.scalahttps://github.com/allenai/sbt-plugins/blob/e661264de9b35aae2a0e2edbad270b4b0cf579e0/src/main/scala/org/allenai/plugins/HelperDefs.scala - 但这些并没有帮助我真正解决这个问题。

也欢迎替代结构。

0 个答案:

没有答案