Paul Rivera
Paul Rivera

Reputation: 63

how to share vals between build.sbt and assembly.sbt

I'm using two files for my build: build.sbt and assembly.sbt (for building fat jars using sbt-assembly plugin). I have some vals defined in build.sbt. Let's just say I'm doing some custom tasks that depend on them. However, I noticed that vals defined in build.sbt are not visible in assembly.sbt. So I end up duplicating code in those two files. How do I configure it such that assembly.sbt can see the vals in build.sbt?

Thanks!

Upvotes: 2

Views: 206

Answers (1)

jsuereth
jsuereth

Reputation: 5624

Currently, val in *.sbt files are meant to be namespace separated. We've debated the merits of having a global namespace or not, but in the end keeping them separate makes things a lot more consistent.

The "sbt" way to share vals and settings between build.sbt is to either:

  • Create a plugin which does so.
  • Create a "library" in the project/ directory which does so.

For option #2, you can do the following:

project/lib.scala

package mylib

object MyStuff {
   val foo = "hi"
}

build.sbt

import mylib.MyStuff

// Just reference .scala code from the project/ directory.
name := MyStuff.foo

Hope that helps!

Upvotes: 2

Related Questions