Building a runnable scala jar file with akka library as dependency


(Sven Richter) #1

Hi,

i created a small scala application which uses akka (http://akka.io) as a dependency. Now when i try to create a fat jar to be able to execute that standalone i get a problem with akka. My jar task is very basic: jar {

from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }

manifest { attributes ‘Main-Class’: ‘de.sveri.scala.scspider.Main’ } } and it does what it should besides one thing. Akka uses a configuration file which is merged from different libraries (see the second warning “When using JarJar, OneJar, Assembly or any jar-bundler” on this page: http://doc.akka.io/docs/akka/snapshot/general/configuration.html) while trying to create the jar.

The jar task just adds two different versions of the same config file into the jar, which is not sufficient enough to make it work. I read that you somehow have to merge them and it works if i do manually. However, i dont want to use such a great build tool and then still have to do some manual work afterwards. Is there a way to solve that issue? I read that there are plugins for maven and sbt which are able to merge that file, however, i dont want to use them as i like the simplicity of gradle very much (See this post for instance: http://letitcrash.com/post/21706121997/follow-up-sbt-assembly-now-likes-reference-conf).

Best Regards, Sven


(Sven Richter) #2

I just tried it as a sbt build with the https://github.com/sbt/sbt-assembly/ plugin. The jar that is created works and what is does is simply add the contents of reference.conf2 to reference.conf and name it reference.conf.

Isnt there a way to accomplish something like this with gradle?

Best Regards, Sven


(Peter Niederwieser) #3

I recommend to use the gradle-one-jar plugin. Such a solution is safer and less effort than merging Jar entries.


(Sven Richter) #4

Thank you very much Peter,

I was only trying the fatjar plugin (https://github.com/musketyr/gradle-fatjar-plugin) which did not do it very succesfully. However, the gradle-one-jar plugin works great.

Best Regards, Sven