sbt-assembly
sbt-assembly copied to clipboard
Allow resources for assembly jar (only for assembly)
Use case:
Consider a project that serves as a library, but also provides a standalone tool packaged with sbt-assembly.
Now, as a library, some resources must not be included in the main jar (e.g: application.conf
,logback.xml
,etc'...),
And should be provided by the application that depends on the library.
For the standalone tool however, we need to supply such files.
I couldn't figure out how to do so, and I suspect it's not possible (easily).
Ideally I would be happy with either dropping such resources under src/assembly/resources
,
or adding to build.sbt
something like: resourceDirectory in assembly := sourceDirectory.value / "assembly"
.
(or something equivalent)
I think sbt-pack is better for this job
I use sbt-pack to get a directory with jars in lib dir.
But sometimes, you'll need a single runnable jar.
(The "need" doesn't have to be technically... sometimes bureaucracy gets in the way...)
as a library, some resources must not be included in the main jar
I'm confused here since you also said you need a single runnable jar. Also, I believe the resources files are assembled if they are under src/main/resources
.
Ok, my scenario is this: A multi project, with many subprojects. One module, is a dependency of other modules, but also provides a tool, packaged with assembly, to debug this module's functionality.
I can't have application.conf
or logback.xml
files in main/resources
, since these will be pulled together with (in) the module's jar as a dependency for other modules.
But I do want to customize config & logging in the debugging tool.
Try adding resourceDirectory in Compile := baseDirectory.value / "src" / "assembly" / "resources"
But wouldn't it add the files there also to main jar?
You may pass in a flag to only customize the resource directory when needed, like sbt -Ddebug=true assembly
resourceDirectory in Compile := {
if (System.getProperty("debug") == "true") {
baseDirectory.value / "src" / "assembly" / "resources"
} else {
(resourceDirectory in Compile).value
}
}
That's a nice workaround (Thanks! I'll probably use commands tt do it in a similar way to what I did here: https://gist.github.com/hochgi/e0dd854a8774414cd750 ). So, I'll use it for now, but I do think though, that the usecase is general enough, and that it would be beneficial to many to have it as part of the plugin functionality.
Hello, we need the same feature as mentioned above: the ability to add a single file only during assembly. Functionality is very similar to maven assembly plugin and custom fileSet
entry in assembly.xml
:
<!-- We only want to include the logback.xml in the fat jar distribution. Not when any other project depends on this module. -->
<fileSets>
<fileSet>
<directory>src/main/assembly-resources</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>