sbt 0.13.5を使用していることに注意してください。Typesafe Activator 1.2.3 でも動作します (sbt 0.13.5 に基づいているため)。
assembly
は構成ではなくタスクであり、設定を提供しないresourceGenerators
ため、エラー - undefined setting
.
ただし、特定の構成でタスクの設定を行うことができるため、次のようにするとうまくいきます。
resourceGenerators in (Runtime, assembly) += myResourceGeneratingTask.taskValue
0.13で推奨されるアプローチである組み合わせ+=
を使用することに注意してください。また、必要に応じて他のユースケースで再利用できるようにtaskValue
する方法も抽出しました。sbt の公式ドキュメントのファイルの生成def makeSomeSources
を参照してください。
実行後の値ではなく、タスクを追加したいのでtaskValue
、通常の値の代わりに使用します。Compile
生成されたファイルがメイン ( ) リソースであるかテスト ( ) リソースであるかに応じてスコープを設定する必要がありますTest
。
あなたの場合、それは構成中のassembly
タスクRuntime
です。
参考に使用したbuild.sbt :
import AssemblyKeys._
assemblySettings
def makeSomeSources(f: File): Seq[File] = {
val content = "Hello"
IO.write(f, content)
Seq(f)
}
lazy val myResGenT = taskKey[Seq[File]]("My personal resgen")
myResGenT := {
val log = streams.value.log
val f = (resourceManaged in Compile).value / "resgen.xml"
val fs: Seq[File] = makeSomeSources(f)
log.info(s"Generating file(s): $fs")
fs
}
resourceGenerators in Compile += myResGenT.taskValue
resourceGenerators in Runtime += myResGenT.taskValue
resourceGenerators in (Runtime, assembly) += myResGenT.taskValue
実行runtime:assembly
すると、次の出力が得られます。
> runtime:assembly
[info] Generating file(s): List(C:\dev\sandbox\resourceGenerators\target\scala-2.10\resource_managed\main\resgen.xml)
[info] Including: scala-library.jar
[info] Checking every *.class/*.jar file's SHA-1.
[info] Merging files...
[warn] Merging 'META-INF\MANIFEST.MF' with strategy 'discard'
[warn] Strategy 'discard' was applied to a file
[info] SHA-1: 875d4b95f38dc85d14e53bdcd10e442520aeeefd
[info] Packaging C:\dev\sandbox\resourceGenerators\target\scala-2.10\resourcegenerators-assembly-0.1-SNAPSHOT.jar ...
[info] Done packaging.