Read application.conf from build.sbt

I found many similar questions, but some of them remained unanswered and others did not work for me.
My task is to read application.conf from build.sbt to save the whole configuration in one place. But my build.sbt with code

import com.typesafe.config._ val conf = com.typesafe.config.ConfigFactory.parseFile(new File("conf/application.conf")).resolve() version := conf.getString("app.version") 

do not compile with an error

 error: object typesafe is not a member of package com 

How to solve this problem?

+5
source share
2 answers

To do this, it’s important to know that sbt projects have a recursive structure, so when you run sbt, you actually run the project with the project root folder in the root project.

Considering that to fix your problem you need to add typesafe-config as a library dependency and for your sbt project; To do this, add build.sbt to the project folder of your root project and specify the dependency there, as you usually did (i.e. libraryDependencies += ... ).

+6
source

Use this in your code

 import com.typesafe.config.{Config, ConfigFactory} private val config = ConfigFactory.load() 

and in the build.sbt file

 libraryDependencies += "com.typesafe" % "config" % "1.3.0" 
+2
source

All Articles