I have a multi-module SBT build consisting of api
, core
and third-party
. The structure is roughly this:
api
|- core
|- third-party
The code for third-party
implements api
and is copied verbatim from somewhere else, so I don't really want to touch it.
Because of the way third-party
is implemented (heavy use of singletons), I can't just have core
depend on third-party
. Specifically, I only need to use it via the api
, but I need to have multiple, isolated copies of third-party
at runtime. (This allows me to have multiple "singletons" at the same time.)
If I'm running outside of my SBT build, I just do this:
def createInstance(): foo.bar.API = {
val loader = new java.net.URLClassLoader("path/to/third-party.jar", parent)
loader.loadClass("foo.bar.Impl").asSubclass(classOf[foo.bar.API]).newInstance()
}
But the problem is that I don't know how to figure out at runtime what I should give as an argument to URLClassLoader
if I'm running via sbt core/run
.
sbt-assembly
bundleapi
,core
and the Scala library andthird-party.jar
separately.object
), e.g. the path to the external process. My code needs to be able to deal with multiple locations of that external process.