sbt / sbt-buildinfo

I know this because build.sbt knows this.
MIT License
551 stars 88 forks source link

buildInfoRenderer doesn't seem to be respected #95

Closed alexeyr closed 7 years ago

alexeyr commented 8 years ago

In build.sbt I have

lazy val extraClassPathTask = TaskKey[String]("extraClassPath")

// Requires luaBackendCore and lmsBackendLinAlg to be compiled but not on classpath,
// to demonstrate plugin system
lazy val examples = Project("scalan-examples", file("examples")).
  dependsOn(core % "compile->compile;test->test;it->test", linalg).configs(IntegrationTest).settings(itSettings).
  enablePlugins(BuildInfoPlugin).settings(
    buildInfoKeys := Seq(extraClassPathTask),
    buildInfoRenderer := ConfBuildInfoRenderer(buildInfoOptions.value)
  )

extraClassPathTask in examples := ...

ConfBuildInfoRenderer is

import sbtbuildinfo._

case class ConfBuildInfoRenderer(options: Seq[BuildInfoOption]) extends BuildInfoRenderer {
  def fileType = BuildInfoType.Resource
  def extension = "conf"
  def header = Nil
  def footer = Nil

  // TODO any other needed types
  def render(result: BuildInfoResult) = {
    val rhs = result.typeExpr match {
      case TypeExpression("String", Nil) =>
        "\"" + result.value.toString + "\""
      case _ =>
        result.value.toString
    }
    s"""${result.identifier}=$rhs"""
  }

  def renderKeys(infoKeysNameAndValues: Seq[BuildInfoResult]): Seq[String] = infoKeysNameAndValues.map(render)
}

and show scalan-examples/buildInfoRenderer shows [info] ConfBuildInfoRenderer(List()).

However, I still get src_managed/main/sbt-buildinfo/BuildInfo.scala instead of expected resource_managed/sbt-buildinfo/BuildInfo.conf.

You can see the full build.sbt at https://github.com/scalan/scalan/blob/fc8fdd33d8a086ee776fba0429416252aea6ae17/build.sbt. Am I missing something? Plugin version is 0.6.1.

damdev commented 7 years ago

Hi, it seems to be an sbt scopes issue, if you configure the key buildInfoRenderer in the Compile scope it works,

See: https://github.com/damdev/kamon-agent/blob/master/build.sbt#L29

eed3si9n commented 7 years ago

Closing this per https://github.com/sbt/sbt-buildinfo/issues/95#issuecomment-276967193