0
votes

I am trying to extend my build with task that will generate source file. I am defining my task in project/Build.scala like this (non-relevant pieces omitted):

object ProjectBuild extends Build {

  lazy val generateConfiguration = TaskKey[Seq[File]]("generateConfiguration")

  lazy val unscopedSettings = Seq(
    generateConfiguration <<=
      (libraryDependencies, sourceManaged).map { (dependencies, generatedRoot) =>
           // here goes implementation
        },
    sourceGenerators += generateConfiguration.taskValue
  )

  override lazy val settings = super.settings ++ inConfig(Compile)(unscopedSettings)
}

When I try to import project in sbt I get following error:

[info] Loading project definition from ...web/project

References to undefined settings:

{.}/compile:sourceManaged from {.}/compile:generateConfiguration (...web/project/Build.scala:19) Did you mean compile:sourceManaged ?

{.}/compile:sourceGenerators from {.}/compile:sourceGenerators (...web/project/Build.scala:33) Did you mean compile:sourceGenerators ?

I understand that my problem is because I probably reference the setting with wrong scope. I suppose, the issue is within 'this build' ({.}) which for some reason is prepended here (as far as I understand, the setting exists in Global scope for this axis).

How should I correctly express dependency to sourceManaged setting in Compile configuration within Scala code (not .sbt)?

P.S.: sbt 0.13.8

scala 2.11.7

1

1 Answers

0
votes

I seem to have found the issue myself.

Possible reason this did not work was the way I put my custom settings into the build - I tried to override lazy val settings of Build. Since I described my tasks in Build.scala rather than build.sbt which comes before in eventual build definition, it appears that dependent settings are not yet defined! They will be set later by default imports of build.sbt.

Once I moved addition of custom properties in the project to build.sbt while leaving their definition in Build.scala everything worked as expected.

Despite there is information about override order between *.scala and build.sbt and some simple examples of compound build definitions it was not that obvious.