How to add jars into a jar?

I have to build some jars which are Eclipse plugins containing dependent library jars within a ‘lib’ directory.

When I override the ‘jar’-task like this:

jar {
    from "${projectDir}/lib"
 }

the dependent jars will be include, but into the root directory of the target jar.

And when I do this: jar {

from “${projectDir}/lib”

into ‘lib’ } I get a ‘lib’ directory, but the compiled classes will also be found there.

How do I get the compiled classes in the normal order of a jar, plus an additional directory ‘lib’ for my libs’?

You might try:

jar {
   from("$projectDir") {
      include 'lib/**'
   }
}

This way you put the whole lib directory recursively into the jar but do not change the “into”.

Philip

Thanks Philip, this now works as expected!

1 Like