Reputation: 943
I have the following line in my sbt file:
target in Compile in doc := baseDirectory.value / "docs"
This is creates a folder in the directory one level below the one I am aiming for. I would like to get essentially (pseudocode):
parentDirectory = parent of baseDirectory
target in Compile in doc := parentDirectory.value / "docs"
Where now "docs" sits next to the baseDirectory, as opposed to in it.
Is there an easy way to do this?
EDIT: Project Structure
myFolder/project/build.sbt
If I run "docs" in sbt shell, I get the following output:
myFolder/project/docs/
What I want instead is:
myFolder/docs/
myFolder/project/build.sbt
The reason I want to do this is so I can host my docs on github pages in the same directory. This seems the easiest way without complicating stuff.
Upvotes: 0
Views: 1321
Reputation: 48420
Consider standard two successive dots ..
notation to represent parent directory, for example
Compile / doc / target := baseDirectory.value / ".." / "docs"
Alternatively file("..")
could also work
Compile / doc / target := file("../docs")
You might want to create a dedicated setting for reuse
lazy val parentOfBaseDirectory = settingKey[File]("Parent of base directory")
parentOfBaseDirectory := baseDirectory.value / ".."
Couple of side notes:
You can make quick one off experiments within sbt shell using set
and semicolon ;
set Compile/doc/target := baseDirectory.value / ".." / "docs"; doc
The reason /
syntax works is because File
is implicitly converted to sbt's RichFile
which provides additional useful extension methods.
Upvotes: 4
Reputation: 4587
baseDirectory.value
is of type java.io.File
, so you can use all these methods:
https://docs.oracle.com/javase/7/docs/api/java/io/File.html
The relevant one here would be getParentFile
.
Upvotes: 1