Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference to undefined setting error with custom task in SBT?

Tags:

sbt

I'm creating a task in SBT that will create a properly-formatted classpath, but I get an undefined setting error when I try to compile. The error is not useful enough to tell me what setting is undefined:

[error] Reference to undefined setting: 
[error] 
[error]   *:fullClasspath from *:fcp
[error]  

This is for the following build configuration:

import sbt._
import Keys._

object TestBuild extends Build {
    override lazy val settings = super.settings ++ Seq(
        name := "blah", scalaVersion := "2.10.2"
    )

    lazy val fcp = TaskKey[String]("fcp", "create formatted classpath")
    lazy val fcpTask = fcp <<= fullClasspath map { tasks =>
        val cp = tasks.map(_.data.getName + ":")
        s"[Classpath]$cp[/Classpath]"
    }

    lazy val project = Project(
        "project", file("."), settings = settings ++ Seq(fcpTask)
    )
}
like image 770
user2668128 Avatar asked Mar 10 '14 13:03

user2668128


1 Answers

Three things:

1) You're removing all the default settings. When you create a project, you can specify a complete list of settings for the project (like you're currently doing) or you can add your settings configurations to the defaults. If you change your project definition to the following, it should start working:

lazy val project = (
  Project("project", file("."))
  .settings(fcpTask)
)

2) You're placing settings into the Build itself. If these settings don't exist on the Project level, then it will look into the Build for the settings. However, things like name should probable be defined in the project. So your complete build file would look like:

import sbt._
import Keys._

object TestBuild extends Build {
    lazy val fcp = TaskKey[String]("fcp", "create formatted classpath")
    lazy val fcpTask = fcp <<= fullClasspath map { tasks =>
        val cp = tasks.map(_.data.getName + ":")
        s"[Classpath]$cp[/Classpath]"
    }
    lazy val project = (
      Project("project", file("."))
      .settings(name := "blah", scalaVersion := "2.10.2")
      .settings(fcpTask)
    )
}

3) You should select which configuration you want to pull your class path from. Options:

  • Runtime: Includes the project's compiled classes + resource directories and dependencies
  • Compile: Include justs the dependencies used to compile the project
  • Test: Include all the dependencies used when testing (including the proejct itself)

What you had before is equivalent to fullClasspath in Compile IIRC.

Hope that helps!

like image 143
jsuereth Avatar answered Jan 01 '23 15:01

jsuereth