2

I am writing a Build.scala file for sbt which needs to use the base directory of the project. I can't figure out how to get the project path as a String from baseDirectory.

If using build.sbt it works doing

thePath := baseDirectory.value

but when I try to call value from a build.scala I get the error

value can only be used within a task or setting macro, such as :=, +=, ++=, Def.task, or Def.setting

Apparently, baseDirectory is a Def.Initialize[File] instance but I have looked at its code here and I do not fully understand it.

Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
Serg M Ten
  • 5,568
  • 4
  • 25
  • 48

1 Answers1

2

Maybe baseDirectory.value.getAbsolutePath does the trick. Look at this question to see how to get the path for sub-projects.

Thomas Bach
  • 103
  • 7
  • 1
    I think this answers the question. And the link is to a _related_ SO question: complementary, but not essential to the answer. – laughedelic Mar 20 '18 at 17:50