Reference scala file from build.sbt

帅比萌擦擦* 提交于 2020-06-28 05:20:42

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!