Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the idiomatic way for an SBT project to publish 2 artifacts?

I have a project that uses SBT as build system and that combines Scala/Java and native sources with JNI.

To stay as flexible as possible, my current plan to publish this kind of project is to publish two different jars: one containing pure bytecode (the referencing of the native binary is left up to the end-user) and one fat jar that also contains the native libraries and extracts them automatically.

To generate a fat jar, I created a task called packageFat that essentially copies the task packageBin with additional mappings to the native libraries and the suffix '-fat' appended to the name.

The relevant part of the build configuration can be viewed here: https://github.com/jodersky/flow/blob/master/project/nativefat.scala

However, with this kind of configuration, any project that depends on mine and wishes to include the fat jar has to declare a dependency in this form:

libraryDependencies += "<organization>" %% "<name>" % "<version>" artifacts Artifact("<name>-fat", "jar", "jar")

I know that distributing projects using JNI is kind of clumsy, but the part after the last '%', makes the dependency really cumbersome. So my question is: what is the idiomatic way in SBT to publish one normal jar and one fat jar from one project?

like image 315
Jakob Odersky Avatar asked Jan 15 '14 20:01

Jakob Odersky


1 Answers

I would create a multi project build file, with a core sub project that will be published "plain", and a fat sub project which will publish with JNI, and then you could use two different artifact names, like foo-core and foo-fat.

In fact, foo-fat could depend on foo-core, and its own artifact would only consist of the JNI stuff.

like image 135
0__ Avatar answered Sep 30 '22 02:09

0__