ant2009
ant2009

Reputation: 22646

bundle external jar into dependancies for output jar file

I have the following build.gradle file. One of my dependences is json-simple. However, when I create my jar HttpSnapClient that is not included in the jar file.

apply plugin: 'java'         
apply plugin: 'application'  
apply plugin: 'groovy'       

mainClassName = 'com.sunsystem.HttpSnapClient.SnapClient'

repositories {
   mavenLocal()
   mavenCentral()
}

dependencies {
   compile "com.googlecode.json-simple:json-simple:1.1.1"
   testCompile "org.codehaus.groovy:groovy:2.3.3"
   testCompile "org.spockframework:spock-core:0.7-groovy-2.0"
}

jar {
    baseName = 'HttpSnapclient'
    version ='1.0.0'
}

task wrapper(type: Wrapper) {
    gradleVersion = '1.12'
}

I would like to bundle the json-simple.jar into my HttpSnapClient.jar so my application that will use this HttpSnapClient.jar will already have json-simple.jar included.

when I run the following command jar tvf HttpSnapclient-1.0.0.jar

     0 Mon Jun 30 14:37:56 ICT 2014 META-INF/
    25 Mon Jun 30 14:37:56 ICT 2014 META-INF/MANIFEST.MF
   294 Mon Jun 30 14:37:56 ICT 2014 WebServiceResponseCodes.class
     0 Mon Jun 30 14:37:56 ICT 2014 com/
     0 Mon Jun 30 14:37:56 ICT 2014 com/sunsystem/
     0 Mon Jun 30 14:37:56 ICT 2014 com/sunsystem/HttpSnapClient/
  5965 Mon Jun 30 14:37:56 ICT 2014 com/sunsystem/HttpSnapClient/SnapClient.class

There is no json-simple included, so any application that uses this HttpSnapClient will fail as its looking for the json-simple that has not been included.

When I run I get the following: gradle dependencies

:dependencies

------------------------------------------------------------
Root project
------------------------------------------------------------

archives - Configuration for archive artifacts.
No dependencies

compile - Compile classpath for source set 'main'.
\--- com.googlecode.json-simple:json-simple:1.1.1
     \--- junit:junit:4.10
          \--- org.hamcrest:hamcrest-core:1.1

default - Configuration for default artifacts.
\--- com.googlecode.json-simple:json-simple:1.1.1
     \--- junit:junit:4.10
          \--- org.hamcrest:hamcrest-core:1.1

Thanks in advance for any suggestions.

Upvotes: 1

Views: 925

Answers (2)

judoole
judoole

Reputation: 1422

Seems like you are running gradle build instead of gradle distZip or gradle distTar which bundles everything into either a zip og tar. Might be you are more interested in the solution @Opal is suggesting though. Application plugin will create a distribution with a bin folder for startupscripts and a lib for all your jars.

Upvotes: 1

Opal
Opal

Reputation: 84854

Fat Jar is a plugin You're probably looking for. By default dependencies are not included into jar file.

Upvotes: 1

Related Questions