Follow-Up: sbt-assembly now likes reference.conf!

In my last post I said that configuring sbt-assembly to merge our beloved configuration files would not warrant its own plugin. Of course copy-pasting all that code would not have been really that nice either. What a pickle …

Following Mr. Holmes’ logic you will have guessed the solution: big kudos to Eugene for assisting with and merging my patch and releasing sbt-assembly version 0.8.0, which now does the right thing out of the box. It even is very easy to configure to merge other files, too (e.g. application.conf), just have a look at the project page linked above. And if all of that is not enough for your very special use-case, you can easily write your own strategy, which in best SBT tradition is documented here.

HOWTO: sbt-assembly vs. reference.conf

[update: sbt-assembly knows about reference.conf since 0.8.0, see the following post]

One of the things which changed in Akka 2.0 was the new configuration system, which is based upon the assumption that all used settings are defined in resources named “/reference.conf” and found on the classpath. This composes nicely, as then different libraries can coexist in the same project and the configuration systemjust works. One situation where this breaks, however, is when using fat jars for deployment. The problem usually shows up as

ConfigException$Missing: No configuration setting found for key: ‘akka.version’

and the cause is that during packaging of the fat jar only one of the many “reference.conf” files was copied instead of merging them all.

There was a discussion showing a solution when using proGuard, and I thought something similar should be possible using sbt-assembly. Eugene was so nice to add a hook which allows this to work, based on this ticket, so here it goes.

The following of course assumes that the sbt-assembly plugin has been installed in version 0.7.4, for which the following addition is needed:

Then the code to make SBT do the right thing is so little that it does not warrant its own plugin (it only looks long because this blog’s style is like literally writing on the margins of a newpaper):

Making the location of the merged “reference.conf” configurable or merging other things is left as an exercise to the reader.

As a bonus, this adds a “merge-reference” task which you can invoke to perform the merge and show the location:

> show merge-reference
[info] reference.conf