pm42
pm42

Reputation: 19

Read a val defined in build.sbt from a command

I'm writing a command in a project/MyCommand.scala file. I need to access to a val defined in my build.sbt such as:

val scala3 = "3.1.3"

I do not know how to get it from the state.

Thanks.

Upvotes: 0

Views: 126

Answers (1)

MartinHH
MartinHH

Reputation: 1293

The common approach for that would be to define the vals (or defs) you need to access within the project directory, e.g. like this:

// in project/ProjectConstants.scala
object ProjectConstants {
  val Scala3Version = "3.1.3"
}

Then you could access that from both your build.sbt and from other code that resides in the project directory:

// works in both build.sbt and project/MyCommand.scala:
val scala3 = ProjectConstants.Scala3Version

Upvotes: 1

Related Questions