Search code examples
scalasbtquilltypesafe-config

Scala Quill custom config location


I'm using Scala Quill library to work with database and it requires a configuration file as documented here.

My project structure is:

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

Now if I put my config application.conf in folder resources, everything is fine. But I want it to be in config instead because project_2 also uses the file.

So how can I modify my build.sbt to do that?

Here is my current 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")

Solution

  • If you want to share configuration between several modules, I would recommend to use standard way:

    create new module which will contain shared part of config and do project_1 and project_2 dependent on this new module. Call common config as reference.conf to be loaded automatically (see here for details) and put in resources folder in new module.