Coming Up for Air

Building "Fat Jars" with Gradle

Wednesday, Sep 4, 2013 |

Building "Fat Jars " with Gradle

Jason Lee 2013-09-04

Sometimes, such as when building command line Java apps, it would be nice to bundle all of the app's dependencies in a single jar so that the user need not collect and manage these. With Gradle, that can be easily accomplished with the following lines:

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

When you run gradle assemble, you should find your now very hefty jar in build/libs.