sbt: copy resources to classpath in multi project build

1.2k views Asked by At

I have a sbt project with following structure:

project
|
|-- file.json
|-- <serverProject>
|-- <clientProject>

project aggregates both serverProject and clientProject. Starting sbt and compiling works fine.

When running or packaging serverProject I want file.json to end up at the classpath of serverProject.

I added file.json to the unmanagedResources in (Compile) for serverProject but I get following error when trying to run / package:

[info] Done packaging.
java.lang.RuntimeException: Duplicate mappings:
    project/serverProject/target/scala-2.11/classes/file.json
from
    file.json
        project/serverProject/file.json
    at scala.sys.package$.error(package.scala:27)
    at sbt.Sync$.noDuplicateTargets(Sync.scala:67)
    ...

It looks like sbt finds both the project root directory and serverProject directory as candidates for file.json after which it fails.

How to get around this error?

Thanks for reading and helping out!

1

There are 1 answers

0
Kristof On

I was able to solve my issue! When adding following setting to serverProject it works as expected:

unmanagedResources in (Compile) ++= Seq(file(baseDirectory.value.getParentFile.getAbsolutePath + "/file.json"))