How to Fat Jar a Single Dependency


(ambcloses) #1

I know I can fat jar all my compile dependencies by doing:

jar {
  from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}

However, what I would like to do is to fat jar a single compile dependency, instead of them all. I have:

dependencies {
  compile files("myCode-1.0.jar")
  ... lots more dependencies
}
  jar {
  // what should be here to fat jar only myCode-1.0.jar?
  // of course, I also want the classes defined in my project to be included in the jar
  // but i don't want my other dependencies
}

(Carlo Luib-Finetti) #2

if your dependency is a file, just do

jar {
    from file("my-Code-1.0.jar")
}

(ambcloses) #3

Ah, sorry - I have dependencies in ivy coordinates. I just wrote my dependency as a file dependency for the example, my bad.

Thus I have:

dependencies {
  compile "com.group:myCode:1.0"
  compile "org.apache.commons:commons:1.0"
  // etc.
}

and I want to fat jar the jar for myCode-1.0.jar.


(Peter Niederwieser) #4
configurations {
    myCode
}
  dependencies {
    myCode "com.group:myCode:1.0"
}
  jar {
    from configurations.myCode
}

(ambcloses) #5

Peter - that was what I wanted, thank you.