Scala Quill 自定义配置位置

Scala Quill custom config location

我正在使用 Scala Quill library to work with database and it requires a configuration file as documented here

我的项目结构是:

root
|_ config
|_ project_1
|  |_ src
|     |_ main
|         |_ resources
|         |_ scala
|_ project_2

现在,如果我将配置 application.conf 放入文件夹 resources,一切都很好。但我希望它位于 config 中,因为 project_2 也使用该文件。

那么我该如何修改我的build.sbt呢?

这是我现在的 build.sbt:

val commonSettings = Seq(
  version := "1.0.0",
  scalaVersion := "2.11.8",

  libraryDependencies ++= Seq(
    ...
  )
)

val common = (project in file("common"))
  .settings(commonSettings)
  .settings(name := "common")

def newProject(name: String): Project =
  Project(name, file(name))
    .settings(commonSettings)
    .settings(
      mainClass in assembly := Some(s"$name.Main"),
      assemblyJarName in assembly := s"$name.jar"
    )
    .dependsOn(common)

val project_1 = newProject("project_1")

val project_2 = newProject("project_2")

如果你想在多个模块之间共享配置,我建议使用标准方式:

创建新模块,它将包含配置的共享部分,并根据这个新模块执行 project_1project_2。将公共配置调用为reference.conf自动加载(详见here)并放入新模块的resources文件夹中。