I have the following problem: I need to write a file into a build directory with the content that is defined in the project sbt is going to build.
prj
|
|_src/main/scala/FancyScalaFile.scala
|
|_build.sbt
|
|_project/build.properties
Here is how the FancyScalaFile.scala
looks like
object FancyScalaFile {
def extractString: String() = //...
}
Is there a way to call extractString
from build.sbt
?
Yes, you can add additional source directory to project/build.sbt
(create this file if it doesn't exist; do not confuse it with build.sbt
in the project root directory)
Compile / unmanagedSourceDirectories += baseDirectory.value / ".." / "src" / "main" / "scala"
After that you'll be able to call FancyScalaFile.extractString()
in build.sbt
.
For example if FancyScalaFile
is
object FancyScalaFile {
def extractString(): String = "scala-reflect"
}
then you can write the following in build.sbt
libraryDependencies += scalaOrganization.value % FancyScalaFile.extractString() % scalaVersion.value
and project is built successfully adding scala-reflect
dependency.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.