4

How to make gradle to included some dependencies into module resulted jar as jar? i.e. to make jar with nested jar's e.g. in lib folder ?

This is not Android project, and this should be done for many modules in multi-module project, so fatJar, uberJar, shadowJar alike solutions seem not to fit.

Paul Verest
  • 60,022
  • 51
  • 208
  • 332
  • Could you elaborate on how what you're asking for is different from fat/uber/shadow? – RaGe Apr 04 '16 at 03:17
  • fat/uber/shadow are good to produce final artifact, but for multi-module project they are slow, e.g. take 10 jar files extract classes and repack back into new jar. That is my understanding, but if it possible to do nesting with either of them, and those artifact can be used in multi-module project and/or deployed and consumed to/from Maven repository, I would love to hear an answer or any comments pushing me to the right direction. – Paul Verest Apr 04 '16 at 11:36
  • Ah, now I get it. You can do the same thing as many of the fatjar type tasks you can find around here, but skip the `zipTree` directive, which is what does the unpacking. Will post an answer. – RaGe Apr 04 '16 at 13:12

1 Answers1

0

You just need to add an additional from directive to include dependencies in your jar:

task jarJar(type: Jar) {
    baseName = project.name + '-jarjar'
    from { configurations.compile }
    with jar
}
RaGe
  • 22,696
  • 11
  • 72
  • 104
  • Finally got around to testing this, and it works for me. @PaulVerest does this work for you? – RaGe Apr 06 '16 at 13:55
  • This may work for one project, but how to make that the result would be seen in next project that depends on it? I am also learning about bnd as it is OSGi project http://stackoverflow.com/questions/17298263/how-to-add-import-package-instructions-for-runtime-dependencies But let this question and the answer stay for general, non OSGi, multi-module project – Paul Verest Apr 08 '16 at 14:22
  • @PaulVerest you should include the OSGi implications in your question. – RaGe Apr 08 '16 at 14:29
  • I have not, so this question stays as general for gradle multi-module – Paul Verest Apr 08 '16 at 15:13
  • I guess the existing Jar task should be extended, overwritten, so that any other tasks depending on it, would get jar with nested jars – Paul Verest Apr 09 '16 at 15:32