Question: I would like to share a common version variable between an sbtPlugin and the rest of the build

Here is what I am trying:

in `project/Build.scala`:

```
object Versions {
  scalaJs = "0.5.0-M3"
}
object MyBuild extends Build {
  //Use version number
}

```

in `plugins.sbt`:

```
addSbtPlugin("org.scala-lang.modules.scalajs" % "scalajs-sbt-plugin" % Versions.scalaJs)

```

results in

```
plugins.sbt:15: error: not found: value Versions
addSbtPlugin("org.scala-lang.modules.scalajs" % "scalajs-sbt-plugin" % Versions.scalaJs)

```

Is there a way to share the version number specification between `plugins.sbt` and the rest of the build, e.g. `project/Build.scala`?

Answer: 
For the `project/plugins.sbt` file you'd have to have another `project` under `project` with the `Versions.scala` file. That would make the definition of `Versions.scalaJs` visible.

The reason for doing it is that `*.sbt` files belong to a project build definition at the current level with `*.scala` files under `project` to expand on it. And it's...[turtles all the way down](http://en.wikipedia.org/wiki/Turtles_all_the_way_down), i.e. [sbt is recursive](http://www.scala-sbt.org/release/docs/Getting-Started/Full-Def.html#sbt-is-recursive).

I'm not sure how much the following can help, but it might be worth to try out - to share versions between projects - `plugins` and the main one - you'd have to use `ProjectRef` as described in the answer to [RootProject and ProjectRef](https://stackoverflow.com/q/19469708/1305344):

> 
> When you want to include other, separate builds directly instead of
>  using their published binaries, you use "source dependencies". This is
>  what `RootProject` and `ProjectRef` declare. `ProjectRef` is the most
>  general: you specify the location of the build (a URI) and the ID of
>  the project in the build (a String) that you want to depend on. 
>  `RootProject` is a convenience that selects the root project for the
>  build at the URI you specify.
> 
> 
>
My proposal is to hack. For example, in `build.sbt` you can add a task:

```
val readPluginSbt = taskKey[String]("Read plugins.sbt file.")

readPluginSbt := {
        val lineIterator = scala.io.Source.fromFile(new java.io.File("project","plugins.sbt")).getLines
            val linesWithValIterator = lineIterator.filter(line => line.contains("scalaxbVersion"))
            val versionString =  linesWithValIterator.mkString("\n").split("=")(1).trim
            val version = versionString.split("\n")(0) // only val declaration
        println(version)
        version
    }

```

When you call `readPluginSbt` you will see the contents of `plugins.sbt`. You can parse this file and extract the variable.

For example: 

```
resolvers += Resolver.sonatypeRepo("public")

val scalaxbVersion = "1.1.2"

addSbtPlugin("org.scalaxb" % "sbt-scalaxb" % scalaxbVersion)

addSbtPlugin("org.xerial.sbt" % "sbt-pack" % "0.5.1")

```

You can extract `scalaxbVersion` with regular expressions/split:

```
scala> val line = """val scalaxbVersion = "1.1.2""""
line: String = val scalaxbVersion = "1.1.2"

scala>  line.split("=")(1).trim
res1: String = "1.1.2"

```