SBT error: "Runtime reference to undefined setting" - scala

I am trying to reference another Github project as a build dependency in sbt using the following code that sits in build.sbt:
lazy val dependency = RootProject(uri("..."))
// The Play project itself
lazy val root = (project in file("."))
.enablePlugins(Common, PlayScala, GatlingPlugin)
.configs(GatlingTest)
.settings(inConfig(GatlingTest)(Defaults.testSettings): _*)
.dependsOn(dependency)
.settings(
name := """play-scala-rest-api-example""",
scalaSource in GatlingTest := baseDirectory.value / "/gatling/simulation"
)
And I get the error:
Runtime reference to undefined setting:
[error]
[error] ProjectRef(uri("..."), "dependency")

Related

Setting up Cross Compilation for my SBT Auto plugin project

I am writing a SBT Auto Plugin. This is my build.sbt file
lazy val foo = (project in file(".")).settings(
name := "foo",
sbtPlugin := true,
organization := "com.foo",
crossScalaVersions = Seq("2.11.8", "2.12.4")
)
but I get the error
overloaded method value settings with alternatives:
(ss: sbt.Def.SettingsDefinition*)sbt.Project <and>
=> Seq[sbt.Def.Setting[_]]
cannot be applied to (sbt.Def.Setting[String], sbt.Def.Setting[Boolean], sbt.Def.Setting[String], crossScalaVersions: Seq[String])
lazy val foo = (project in file(".")).settings(
^
[error] sbt.compiler.EvalException: Type error in expression
[error] sbt.compiler.EvalException: Type error in expression
[error] Use 'last' for the full log.
Project loading failed: (r)etry, (q)uit, (l)ast, or (i
My objective is that when I do sbt publish I publish two jar files. one for scala 2.11 and other for scala 2.12
you have to give it like crossScalaVersions := Seq("2.11.8", "2.12.4") instead of crossScalaVersions = Seq("2.11.8", "2.12.4").
You can see more here Cross-Building a Project.

SBT Run Main Method from a Sub Project

I am writing a project which contains scala macros. This is why I have organized my project into two sub projects called "macroProj" and "coreProj". The "coreProj" depends on "macroProj" and also contains the main method to run my code.
My requirement is that when I do a sbt run from the root project, the main method is taken from the coreProj sub project. I search and found a thread which has a solution for this
sbt: run task on subproject
Based on this my build.sbt looks like
lazy val root = project.aggregate(coreProj,macroProj).dependsOn(coreProj,macroProj)
lazy val commonSettings = Seq(
scalaVersion := "2.11.7",
organization := "com.abhi"
)
lazy val coreProj = (project in file("core"))
.dependsOn(macroProj)
.settings(commonSettings : _*)
.settings(
mainClass in Compile := Some("demo.Usage")
)
lazy val macroProj = (project in file("macro"))
.settings(commonSettings : _*)
.settings(libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value)
mainClass in Compile <<= (run in Compile in coreProj)
But when I do sbt run from the root directory. I get an error
/Users/abhishek.srivastava/MyProjects/sbt-macro/built.sbt:19: error: type mismatch;
found : sbt.InputKey[Unit]
required: sbt.Def.Initialize[sbt.Task[Option[String]]]
mainClass in Compile <<= (run in Compile in coreProj)
^
[error] Type error in expression
In sbt, mainClass is a task that will return an entry point to your program, if any.
What you want to do is to have mainClass be the value of mainClass in coreProj.
You can achieve that this way:
mainClass in Compile := (mainClass in Compile in coreProj).value
This could also be achieved with
mainClass in Compile <<= mainClass in Compile in coreProj
However, the preferred syntax is (...).value since sbt 0.13.0.

sbt multi project undefined settings

I have a multi project setup in SBT. In our build process there's a file in the project that is automatically updated by our CI. It contains the app version.
However, whenever I try to load the app settings, I get an error similar to the following:
[error] References to undefined settings:
[error]
[error] module1/*:appProperties from module1/*:version (/Users/jespeno/workspace/multi-module/build.sbt:10)
[error]
[error] module2/*:appProperties from module2/*:version (/Users/jespeno/workspace/multi-module/build.sbt:10)
This is what my sbt file looks like:
val appProperties = settingKey[Properties]("app version")
appProperties := {
val prop = new Properties()
IO.load(prop, new File("version.properties"))
prop
}
val commonSettings = Seq(
version := appProperties.value.getProperty("project.version"),
scalaVersion := "2.11.7"
)
lazy val root = (project in file(".")).settings(commonSettings: _*)
.aggregate(module1, module2)
.settings(
name := appProperties.value.getProperty("project.name")
)
lazy val module1 = (project in file("./modules/module1"))
.settings(commonSettings: _*)
.settings(
name := "module1"
)
lazy val module2 = (project in file("./modules/module2"))
.settings(commonSettings: _*)
.settings(
name := "module2"
)
Here's my version.properties:
project.name="multi-module"
project.version="0.0.1"
The interesting thing is, the root project is able to load the settings correctly: if I remove the sub-modules, the build starts correctly. I'm using SBT version 0.13.8.
This is caused by appProperties not being visible to submodules(module1, module2), you can change it to:
appProperties in Global := {
val prop = new Properties()
IO.load(prop, new File("version.properties"))
prop
}
sbt scopes

"Reference to undefined setting" error with custom task using a custom configuration in SBT?

I'm trying to create a task in sbt that will output the full classpath of a custom Configuration, but I get an undefined setting error when sbt tries to load the project definition. I can't figure out which setting has to be defined:
import sbt.Keys._
import sbt._
object FoobarBuild extends Build {
lazy val ZK = config("zk")
lazy val fcp = TaskKey[String]("fcp", "create formatted classpath")
lazy val fcpTask = fcp <<= (fullClasspath in ZK) map { cp =>
println(cp.files.absString)
cp.files.absString
}
lazy val project = Project("foobar", file(".")).
configs(ZK).
settings(
name := "foobar",
version := "1.0",
scalaVersion := "2.11.7"
).
settings(fcpTask)
}
Error:
[info] Loading project definition from foobar/project
Reference to undefined setting:
zk:fullClasspath from *:fcp (/Users/gaston/mesosphere/foobar/project/Build.scala:7)
zk:fullClasspath on the 7th line of this file is, of course, fullClasspath in ZK. It's undefined because it isn't set or inherited from any other config, I believe.

How to generate links to standard library types in scaladoc?

I'm using sbt 0.13.7 and Scala 2.11.4.
In my build.sbt, I have:
autoAPIMappings := true
and in a File.scala:
/** scaladoc link to [[scala.concurrent.duration.FiniteDuration]] */
When running sbt doc, I’m getting:
[warn] ...:5: Could not find any member to link for "scala.concurrent.duration.FiniteDuration".
[warn] /** scaladoc link to [[scala.concurrent.duration.FiniteDuration]] */
[warn] ^
Now, when I replace autoAPIMappings := true with:
apiMappings += (scalaInstance.value.libraryJar ->
url(s"http://www.scala-lang.org/api/${scalaVersion.value}/"))
the compiler still gives the warning.
What could be a solution?
I wasn't able to reproduce this behavior using sbt 0.13.7 and Scala 2.11.4.
Do you have multi-project setup? If so make sure to explicitly add settings to each project, or define the common settings in ThisBuild scope.
project/build.properties
sbt.version=0.13.7
build.sbt
lazy val commonSettings = Seq(
scalaVersion := "2.11.4",
autoAPIMappings := true
)
lazy val root = (project in file(".")).
aggregate(app).
settings(commonSettings: _*)
lazy val app = (project in file("app")).
settings(commonSettings: _*)
src/main/scala/Hello.scala
/** scaladoc link to [[scala.concurrent.duration.FiniteDuration]] */
object Hello extends App {
}