问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/61959688/reference-scala-file-from-build-sbt