0

In gradle, when i am trying to build each modules, I need the external dependency also packaged inside Jar as Jar.

Below is few dependencies listed out:

dependencies {
    compile group: 'org.springframework.integration', name: 'spring-integration-xml', version:'4.1.6.RELEASE'
    compile group: 'org.springframework', name: 'spring-oxm', version:'3.0.0.RELEASE'
....
    } 
jar {
    manifest{
     attributes 'Main-Class':'com.MyfirstClass'
    }
}

At the end, when we tried to view Jar it should contain dependent Jars inside lib as shown below

jar tvf build/libs/test.jar
                   META-INF/
                   META-INF/MANIFEST.MF
                   lib/
                   lib/spring-integration-xml.4.1.6.jar
                   .....

Thanks in Advance!

Ragubathi U
  • 321
  • 2
  • 3
  • 18

1 Answers1

0
jar {
    from(configurations.runtime) {
        into 'lib'
    }
}
Vampire
  • 35,631
  • 4
  • 76
  • 102
  • Thanks for prompt reply.but it doesn't work. Its not collecting external dependency as jar – Ragubathi U Apr 12 '16 at 04:48
  • Are you sure you did it correctly? I just tested and it works fine. The initial version did stuff all under `lib` but the libs were there. I updated the example in my answer so that only the libs are stored in the `lib` directory and tried it out with your buildfile. Works like a charm. – Vampire Apr 12 '16 at 08:51
  • then you are still doing it wrongly, as it works fine. ;-) Show what you tried. – Vampire Apr 12 '16 at 16:22
  • is this distinct from an uber jar or fat jar? – Thufir Aug 18 '17 at 12:38
  • A far jar has all dependencies unzipped and their files put into the main jar. Whatever OP uses (I guess one of the spring dependencies he mentioned) takes the libs as JARs from the JAR. So yes, this is different. (And I actually dislike both solutions. :-D) – Vampire Aug 18 '17 at 12:46