scala - SBT - Multi project merge strategy and build sbt structure when using assembly -
i have project consists of multiple smaller projects, dependencies upon each other, example, there utility project depends upon commons project. other projects may or may not depend upon utilities or commons or neither of them.
in build.sbt have assembly merge strategy @ end of file, along tests in assembly being {}.
my question is: correct, should each project have own merge strategy , if so, others depend on inherit strategy them? having merge strategy contained within of project definitions seems clunky , mean lot of repeated code.
this question applied tests well, should each project have line whether tests should carried out or not, or inherited?
thanks in advance. if knows of link sensible (relatively complex) example that'd great.
in day job work on large multi-project. unfortunately closed source can't share specifics, can share guidance.
create
rootsettings
used root/container project, since isn't part of assembly or publish step. contain like:lazy val rootsettings := seq( publishartifact := false, publishartifact in test := false )
create
commonsettings
shared subprojects. place base/shared assembly settings here:lazy val commonsettings := seq( // use common directory of artifacts assemblyoutputpath in assembly := basedirectory.value / "assembly" / (name.value + "-" + version.value + ".jar"), // one-time, global setting if projects // use same folder, should here if modified // per-project paths. cleanfiles <+= basedirectory { base => base / "assembly" }, test in assembly := {}, assemblymergestrategy in assembly := { case "build" => mergestrategy.discard case "logback.xml" => mergestrategy.first case other: => mergestrategy.defaultmergestrategy(other) }, assemblyexcludedjars in assembly := { val cp = (fullclasspath in assembly).value cp filter { _.data.getname.matches(".*finatra-scalap-compiler-deps.*") } } )
each subproject uses
commonsettings
, , applies project-specific overrides:lazy val fubar = project.in(file("fubar-folder-name")) .settings(commonsettings: _*) .settings( // project-specific settings here. assemblymergestrategy in assembly := { // fubar-specific strategy case "fubar.txt" => mergestrategy.discard case other: => // apply inherited "common" strategy val oldstrategy = (assemblymergestrategy in assembly).value oldstrategy(other) } ) .dependson( yourcoreproject, // ... )
and btw, if using intellij. don't name root project variable
root
, appears project name in recent projects menu.lazy val myprojectroot = project.in(file(".")) .settings(rootsettings: _*) .settings( // ... ) .dependson( // ... ) .aggregate( fubar, // ... )
Comments
Post a Comment