Gradle

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What’s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
To raise new issues or bugs against Gradle, please use forums.gradle.org.
  • Gradle
  • GRADLE-566

fatJar option for building jar-with-dependencies

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: New Feature New Feature
  • Status: Open Open
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None

Description

<shameless copy-paste from the mailing list>

I think I'm missing the concept of 'fat jar' in Gradle. Many times
when I worked on a library/console app I needed to stick all
dependencies in single jar. It would be great if java plugin added
extra task that could produce fat jar (or mavenized:
jar-with-dependencies) out of the box.

It would be easy to provide such a fatJar task for the default jar task. This would be the framework way of doing things (like Maven does).

But it would be much cooler, if there were the pattern fat<JarName> which works for any jar that is related to source directories. To make this possible we need a richer abstraction for source directories which we plan to do for 0.8. If we have such source dir objects you could also define a jar like:

task mySrcJar {
add srcDir // srcDir is not String but a rich object, which knows all of the srcDir including its classpath
fat = true
}

This would work with any project layout, not just with single src root projects. And it would enable to provide a rule for a pattern like above.

Toolset over Framework rules

<you bet!>

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • History
  • Activity
  • TeamCity
  • Commits
  • Source
  • Reviews
Hide
Permalink
Tomek Kaczanowski added a comment - 24/Sep/09 5:27 AM

Hi Szczepan,

Thomas Kinnen was kind to provide a solution for fat-jar creation - see http://docs.codehaus.org/display/GRADLE/Cookbook#Cookbook-Creatingafatjar

It is not a fully-fledged solution, but can be sufficient in some cases.

–
Tomek

Show
Tomek Kaczanowski added a comment - 24/Sep/09 5:27 AM Hi Szczepan, Thomas Kinnen was kind to provide a solution for fat-jar creation - see http://docs.codehaus.org/display/GRADLE/Cookbook#Cookbook-Creatingafatjar It is not a fully-fledged solution, but can be sufficient in some cases. – Tomek
Hide
Permalink
Hans Dockter added a comment - 20/Jan/10 3:25 AM

We are kind of conservative to making our API bigger. We want to be really sure that its worth it. With the newest Gradle there is now a fantastic way to 'stage' potential API enhancement candidates. Any script can now be a plugin. Those scripts can live on your local machine or remotely.

I have added a fatjar plugin script. You can say now (with the latest Gradle):

apply url: 'http://github.com/hansd/huglins/raw/master/fatjar.gradle'

jar {
   merge configurations.runtime
}

task otherJar {
   merge files(fileTree('lib').matching { include '**/.jar' })
}
Show
Hans Dockter added a comment - 20/Jan/10 3:25 AM We are kind of conservative to making our API bigger. We want to be really sure that its worth it. With the newest Gradle there is now a fantastic way to 'stage' potential API enhancement candidates. Any script can now be a plugin. Those scripts can live on your local machine or remotely. I have added a fatjar plugin script. You can say now (with the latest Gradle):
apply url: 'http://github.com/hansd/huglins/raw/master/fatjar.gradle'

jar {
   merge configurations.runtime
}

task otherJar {
   merge files(fileTree('lib').matching { include '**/.jar' })
}
Hide
Permalink
Ben McCann added a comment - 25/Jan/11 7:31 PM

I would very much like to see something along the lines of the Maven Assembly Plugin's jar-with-dependencies added.

Hans, I attempted to use the plugin you posted and recieved:
No such property: url for class: org.gradle.api.internal.plugins.DefaultObjectConfigurationAction

Show
Ben McCann added a comment - 25/Jan/11 7:31 PM I would very much like to see something along the lines of the Maven Assembly Plugin's jar-with-dependencies added. Hans, I attempted to use the plugin you posted and recieved: No such property: url for class: org.gradle.api.internal.plugins.DefaultObjectConfigurationAction
Hide
Permalink
Ben McCann added a comment - 25/Jan/11 7:49 PM

I tried the following and it seemed to load the script though it looks like there are problems with the script still:
apply from: 'https://github.com/hansd/huglins/raw/master/fatjar.gradle'

Show
Ben McCann added a comment - 25/Jan/11 7:49 PM I tried the following and it seemed to load the script though it looks like there are problems with the script still: apply from: 'https://github.com/hansd/huglins/raw/master/fatjar.gradle'
Hide
Permalink
Robert Fischer added a comment - 25/Jan/11 7:54 PM

BTW, I've got a OneJar plugin: https://github.com/RobertFischer/gradle-plugins

Show
Robert Fischer added a comment - 25/Jan/11 7:54 PM BTW, I've got a OneJar plugin: https://github.com/RobertFischer/gradle-plugins
Hide
Permalink
Ben McCann added a comment - 25/Jan/11 8:12 PM

Thanks, Robert. I'm anxious to try it out. I'm getting the error message below right now:
Cause: Could not find property 'com' on project

I have a multi-maven project. I've attached the build.gradle file from the parent project where I included the plugin in case you see anything obvious that I did wrong (which is likely since I'm still new to gradle :o)

Thanks,
Ben

Show
Ben McCann added a comment - 25/Jan/11 8:12 PM Thanks, Robert. I'm anxious to try it out. I'm getting the error message below right now: Cause: Could not find property 'com' on project I have a multi-maven project. I've attached the build.gradle file from the parent project where I included the plugin in case you see anything obvious that I did wrong (which is likely since I'm still new to gradle :o) Thanks, Ben
Hide
Permalink
Ben McCann added a comment - 25/Jan/11 10:54 PM

I updated my build script, but still cannot get Robert's plugin to work. I didn't realize the first time around that buildscript was a reserved word in gradle. I'm still getting the same error:
Caused by: groovy.lang.MissingPropertyException: Could not find property 'com' on project

Show
Ben McCann added a comment - 25/Jan/11 10:54 PM I updated my build script, but still cannot get Robert's plugin to work. I didn't realize the first time around that buildscript was a reserved word in gradle. I'm still getting the same error: Caused by: groovy.lang.MissingPropertyException: Could not find property 'com' on project
Hide
Permalink
Ben McCann added a comment - 25/Jan/11 11:06 PM

Finally got it figured out. I left "Plugin" off the plugin name. I filed a new bug (http://jira.codehaus.org/browse/GRADLE-1352) asking for Gradle to give back a better error message in this situation. I'll try out the plugin now and let you know how it works. Thanks!

Show
Ben McCann added a comment - 25/Jan/11 11:06 PM Finally got it figured out. I left "Plugin" off the plugin name. I filed a new bug (http://jira.codehaus.org/browse/GRADLE-1352) asking for Gradle to give back a better error message in this situation. I'll try out the plugin now and let you know how it works. Thanks!
Hide
Permalink
Ben McCann added a comment - 25/Jan/11 11:29 PM

I'm sorry, I still can't figure this out. Robert, could you post an example of how to use the plugin? I have it installed now, but am not sure how to call it.

Show
Ben McCann added a comment - 25/Jan/11 11:29 PM I'm sorry, I still can't figure this out. Robert, could you post an example of how to use the plugin? I have it installed now, but am not sure how to call it.
Hide
Permalink
Peter Niederwieser added a comment - 26/Jan/11 9:44 AM

Have you tried gradle oneJar?

Show
Peter Niederwieser added a comment - 26/Jan/11 9:44 AM Have you tried gradle oneJar?
Hide
Permalink
Ben McCann added a comment - 26/Jan/11 12:16 PM

Yep, no luck.

$ gradle oneJar
:unpackOneJar SKIPPED
:typedefOneJar
:java/com/benmccann/test/db:compileJava UP-TO-DATE
:java/com/benmccann/test/db:processResources UP-TO-DATE
:java/com/benmccann/test/db:classes UP-TO-DATE
:java/com/benmccann/test/db:jar UP-TO-DATE
:java/com/benmccann/test/backend:compileJava UP-TO-DATE
:java/com/benmccann/test/backend:processResources UP-TO-DATE
:java/com/benmccann/test/backend:classes UP-TO-DATE
:java/com/benmccann/test/backend:jar UP-TO-DATE
:java/com/benmccann/test/backend:oneJar

FAILURE: Build failed with an exception.

  • Where:
    Build file '/home/bmccann/workspace/test/java/com/benmccann/test/backend/build.gradle'
  • What went wrong:
    Execution failed for task ':java/com/benmccann/test/backend:oneJar'.
    Cause: Problem: failed to create task or type one-jar
    Cause: The name is undefined.
    Action: Check the spelling.
    Action: Check that any custom tasks/types have been declared.
    Action: Check that any <presetdef>/<macrodef> declarations have taken place.
Show
Ben McCann added a comment - 26/Jan/11 12:16 PM Yep, no luck. $ gradle oneJar :unpackOneJar SKIPPED :typedefOneJar :java/com/benmccann/test/db:compileJava UP-TO-DATE :java/com/benmccann/test/db:processResources UP-TO-DATE :java/com/benmccann/test/db:classes UP-TO-DATE :java/com/benmccann/test/db:jar UP-TO-DATE :java/com/benmccann/test/backend:compileJava UP-TO-DATE :java/com/benmccann/test/backend:processResources UP-TO-DATE :java/com/benmccann/test/backend:classes UP-TO-DATE :java/com/benmccann/test/backend:jar UP-TO-DATE :java/com/benmccann/test/backend:oneJar FAILURE: Build failed with an exception.
  • Where: Build file '/home/bmccann/workspace/test/java/com/benmccann/test/backend/build.gradle'
  • What went wrong: Execution failed for task ':java/com/benmccann/test/backend:oneJar'. Cause: Problem: failed to create task or type one-jar Cause: The name is undefined. Action: Check the spelling. Action: Check that any custom tasks/types have been declared. Action: Check that any <presetdef>/<macrodef> declarations have taken place.
Hide
Permalink
Peter Niederwieser added a comment - 26/Jan/11 4:24 PM

Please provide such information upfront rather than letting us guess what the problem might be.

I can confirm that the OneJar plugin doesn't work for multi-project builds, at least not with Gradle 0.9.2.

Show
Peter Niederwieser added a comment - 26/Jan/11 4:24 PM Please provide such information upfront rather than letting us guess what the problem might be. I can confirm that the OneJar plugin doesn't work for multi-project builds, at least not with Gradle 0.9.2.
Hide
Permalink
Ben McCann added a comment - 26/Jan/11 4:43 PM

Thanks. I wasn't sure that "gradle oneJar" was the correct invocation since there were no docs. I filed a bug requesting that it be clarified: https://github.com/RobertFischer/gradle-plugins/issues/issue/3

I also filed a bug for the fact that it's broken on multi-project builds:
https://github.com/RobertFischer/gradle-plugins/issues/issue/4

Show
Ben McCann added a comment - 26/Jan/11 4:43 PM Thanks. I wasn't sure that "gradle oneJar" was the correct invocation since there were no docs. I filed a bug requesting that it be clarified: https://github.com/RobertFischer/gradle-plugins/issues/issue/3 I also filed a bug for the fact that it's broken on multi-project builds: https://github.com/RobertFischer/gradle-plugins/issues/issue/4
Hide
Permalink
Robert Fischer added a comment - 26/Jan/11 4:48 PM

I'm on it.

Show
Robert Fischer added a comment - 26/Jan/11 4:48 PM I'm on it.
Hide
Permalink
Ben McCann added a comment - 26/Jan/11 6:05 PM

Awesome. Thanks so much for being super responsive and providing this plugin. I'll be really excited to use it.

Show
Ben McCann added a comment - 26/Jan/11 6:05 PM Awesome. Thanks so much for being super responsive and providing this plugin. I'll be really excited to use it.
Hide
Permalink
Ben McCann added a comment - 01/Feb/11 8:43 PM

It looks like the Gradle Cookbook also has a tip on how to do this, but it doesn't seem to work, so I filed a new bug for that:
http://jira.codehaus.org/browse/GRADLE-1361

Show
Ben McCann added a comment - 01/Feb/11 8:43 PM It looks like the Gradle Cookbook also has a tip on how to do this, but it doesn't seem to work, so I filed a new bug for that: http://jira.codehaus.org/browse/GRADLE-1361
Hide
Permalink
Ravi Teja added a comment - 25/Jul/12 7:42 AM - edited

I created a similar sample project using uberjar example but anyway need this feature.

Code: https://github.com/bond-/gradle-groovy-jar-example/blob/master/build.gradle
Example: http://stackoverflow.com/questions/9749032/create-a-groovy-executable-jar-with-gradle

Show
Ravi Teja added a comment - 25/Jul/12 7:42 AM - edited I created a similar sample project using uberjar example but anyway need this feature. Code: https://github.com/bond-/gradle-groovy-jar-example/blob/master/build.gradle Example: http://stackoverflow.com/questions/9749032/create-a-groovy-executable-jar-with-gradle
Hide
Permalink
Diwaker Gupta added a comment - 18/Sep/12 7:48 PM

I think gradle should provide a standard plugin (or even in core) for this functionality. While there are many "quick" plugins, scripts, snippets and Cookbook recipes to build a fat jar out there, none of them work out of the box for me. Building a working fat jar requires numerous (potential) steps, including but not limited to:

  • excluding 'META-INF/.RSA', 'META-INF/.DSA' etc. to avoid signing issues when building executable jars
  • combining META-INF/services files to avoid failures when applications use the ServiceLoader framework (easy to hit when you build an app that supports multiple JDBC drivers, for instance)
  • combining NOTICE files, LICENSE files and other useful transformations

Basically, a plugin that can match maven shade/assembly in features

Show
Diwaker Gupta added a comment - 18/Sep/12 7:48 PM I think gradle should provide a standard plugin (or even in core) for this functionality. While there are many "quick" plugins, scripts, snippets and Cookbook recipes to build a fat jar out there, none of them work out of the box for me. Building a working fat jar requires numerous (potential) steps, including but not limited to:
  • excluding 'META-INF/.RSA', 'META-INF/.DSA' etc. to avoid signing issues when building executable jars
  • combining META-INF/services files to avoid failures when applications use the ServiceLoader framework (easy to hit when you build an app that supports multiple JDBC drivers, for instance)
  • combining NOTICE files, LICENSE files and other useful transformations
Basically, a plugin that can match maven shade/assembly in features

People

  • Assignee:
    Unassigned
    Reporter:
    Szczepan Faber
Vote (5)
Watch (8)

Dates

  • Created:
    23/Jul/09 3:45 AM
    Updated:
    18/Sep/12 7:48 PM
  • Atlassian JIRA (v5.0.3#729-sha1:bf569e4)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Gradle. Try JIRA - bug tracking software for your team.