Logician
Logician

Reputation: 93

sbt dependsOn, typesafe config merges application.conf

I have a project with two modules, A and B. Each has an application.conf and a local.conf that includes the former. My project's build.sbt file specifies:

B.dependsOn(A % "compile->compile")

It appears that the local.conf for module B is including application.conf for module A, because I am getting an UnresolvedSubstitution exception for substituted values in module A's application.conf when trying to run module B.

I think it is merging the application.conf files. Is there any way to stop it doing this? In particular, can I do it via the build.sbt file?

Upvotes: 1

Views: 766

Answers (1)

Nathaniel Ford
Nathaniel Ford

Reputation: 21239

When you do this:

B.dependsOn(A % "compile->compile")

what happens is that when B is compiled, it executes A compilation and makes it available to B. This means your configuration files in A will be available to B because Type-Safe configuration puts those configurations into the classpath.

The easiest solution is probably to namespace your properties so that module B is only using properties from it's own configuration and never As. (This is a best practice, to keep separation of concerns clear.) If the intent is for B's configuration to override A's 'default' configuration, and assuming A is essentially a library being used by B, following the best practice guideline here and place a resource.conf file in A and an application.conf file in B, since application.conf is higher-priority.

In your case, both A and B rely on common code. In order to preserve separation of concerns, it is best to refactor this common code into it's own library module and have both A and B reference that code. In this manner you can ensure that the properties they both rely on are in C and properties that are properly set by either A or B are in their domain alone.

Upvotes: 1

Related Questions