将工件添加到SBT子项目:引用未定义的设置

时间:2016-07-04 10:18:06

标签: sbt

我有一个多模块SBT项目,我想将一个工件(由自定义任务生成)添加到子模块。 但我总是有一个Reference to undefined setting错误:

Reference to undefined setting: 
  documentation/*:adocPdf from documentation/*:packagedArtifacts ((sbt.BuildExtra) Defaults.scala:1966)

以下是SBT 0.13.11的build.sbt

import sbt.Keys._
import sbt.Project.projectToRef
import sbt._

lazy val commonSettings = Seq(
  scalaVersion := "2.11.8",
  [...]
)

lazy val adocPdf: TaskKey[File] = taskKey[File]("Generate documentation from Asciidoc")
adocPdf := {
  // generate pdf documentation to target/documentation-$version.pdf
  [...]
  file(s"${documentation.base.absolutePath}/target/documentation-${version.value}.pdf")
}

lazy val docPdfArtifact: Artifact = Artifact("documentation", "pdf", "pdf", None, Configurations.Docs :: Nil, None)

lazy val api = (project in file("api"))
    .settings(commonSettings: _*)

lazy val documentation = (project in file("documentation"))
    .settings(commonSettings: _*)
    .settings(addArtifact(docPdfArtifact, adocPdf).settings: _*)

lazy val myProject = (project in file("."))
    .settings(commonSettings: _*)
    .aggregate(api, documentation)

知道什么是错的?

1 个答案:

答案 0 :(得分:2)

我不确定addArtifact上面做了什么,但您需要指定在为给定项目定义adocPdf : TaskKey[File]的任务主体时创建的设置:

lazy val adocPdf: TaskKey[File] = taskKey[File]("Generate documentation from Asciidoc")
lazy val adocPdfSetting = adocPdf := {
  //.. the task definition - return a `file`
}
lazy val documentation = (project in file("documentation"))
  //apply the setting to the project
  .settings(adocPdfSetting)