{"id":3331,"date":"2014-07-29T22:57:37","date_gmt":"2014-07-29T22:57:37","guid":{"rendered":"http:\/\/www.gubatron.com\/blog\/?p=3331"},"modified":"2019-04-25T13:12:46","modified_gmt":"2019-04-25T13:12:46","slug":"gradle-how-to-copy-files-from-another-jar-into-your-resulting-output-jar","status":"publish","type":"post","link":"https:\/\/www.gubatron.com\/blog\/gradle-how-to-copy-files-from-another-jar-into-your-resulting-output-jar\/","title":{"rendered":"GRADLE: How to copy files from another .jar into your resulting output .jar"},"content":{"rendered":"<p>In our project we like to deliver a single jar as the final product, if you need to copy files that live on an existing jar into the Gradle&#8217;s output jar, this example shows you how to do that (and more)<\/p>\n<p>[pastacode lang=&#8221;java&#8221; manual=&#8221;jar%20%7B%0A%2F%2Fthis%20is%20how%20you%20change%20the%20name%20of%20the%20output%20jar%0AarchiveName%3D%E2%80%99frostwire.jar%E2%80%99%0A%0A%2F%2Fsome%20exclusion%20rules%20to%20keep%20your%20.jar%20clean%0Aexclude(%E2%80%98META-INF%2F*.SF%E2%80%99%2C%20%E2%80%98META-INF%2F*.DSA%E2%80%99%2C%20%E2%80%98META-INF%2F*.RSA%E2%80%99%2C%20%E2%80%98META-INF%2F*.MF%E2%80%99)%0A%0A%2F%2Fhere%20we%20grab%20all%20the%20.class%20files%20inside%20messages.jar%20and%20we%20put%20them%20in%20our%20resulting%20jar%0Afrom%20(zipTree(%E2%80%98lib%2Fjars%2Fmessages.jar%E2%80%99))%20%7B%0Ainclude%20%E2%80%98**%2F*.class%E2%80%99%0A%7D%0A%0A%2F%2Fhow%20to%20manipulate%20the%20jar%E2%80%99s%20manifest%0Amanifest%20%7B%0Aattributes%20%E2%80%98Main-Class%E2%80%99%3A%20%E2%80%98com.limegroup.gnutella.gui.Main%E2%80%99%0A%7D%0A%7D&#8221; message=&#8221;&#8221; highlight=&#8221;&#8221; provider=&#8221;manual&#8221;\/]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In our project we like to deliver a single jar as the final product, if you need to copy files that live on an existing jar into the Gradle&#8217;s output jar, this example shows you how to do that (and more) [pastacode lang=&#8221;java&#8221; manual=&#8221;jar%20%7B%0A%2F%2Fthis%20is%20how%20you%20change%20the%20name%20of%20the%20output%20jar%0AarchiveName%3D%E2%80%99frostwire.jar%E2%80%99%0A%0A%2F%2Fsome%20exclusion%20rules%20to%20keep%20your%20.jar%20clean%0Aexclude(%E2%80%98META-INF%2F*.SF%E2%80%99%2C%20%E2%80%98META-INF%2F*.DSA%E2%80%99%2C%20%E2%80%98META-INF%2F*.RSA%E2%80%99%2C%20%E2%80%98META-INF%2F*.MF%E2%80%99)%0A%0A%2F%2Fhere%20we%20grab%20all%20the%20.class%20files%20inside%20messages.jar%20and%20we%20put%20them%20in%20our%20resulting%20jar%0Afrom%20(zipTree(%E2%80%98lib%2Fjars%2Fmessages.jar%E2%80%99))%20%7B%0Ainclude%20%E2%80%98**%2F*.class%E2%80%99%0A%7D%0A%0A%2F%2Fhow%20to%20manipulate%20the%20jar%E2%80%99s%20manifest%0Amanifest%20%7B%0Aattributes%20%E2%80%98Main-Class%E2%80%99%3A%20%E2%80%98com.limegroup.gnutella.gui.Main%E2%80%99%0A%7D%0A%7D&#8221; message=&#8221;&#8221; highlight=&#8221;&#8221; provider=&#8221;manual&#8221;\/]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[15],"tags":[1414,1437,1227,1409,1413,583],"class_list":["post-3331","post","type-post","status-publish","format-standard","hentry","category-code","tag-build","tag-code","tag-examples","tag-gradle","tag-jars","tag-java"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5Unzf-RJ","jetpack-related-posts":[{"id":3315,"url":"https:\/\/www.gubatron.com\/blog\/gradle-how-to-add-a-list-of-local-jars-to-the-build-classpath\/","url_meta":{"origin":3331,"position":0},"title":"GRADLE: How to add a list of local .jar files to the build classpath","author":"gubatron","date":"July 29, 2014","format":false,"excerpt":"Sometimes you don't want\/cant use maven repos, all you have is a bunch of local jars on disk that you want to use as part of your compilation classpath, and the freaking gradle documentation is too vague. Here is an example: [pastacode lang=\"java\" manual=\"dependencies%20%7B%0Acompile%20files(%E2%80%98lib%2Fjars%2Fgettext-commons.jar%E2%80%99%2C%0A%E2%80%98lib%2Fjars%2Flucene-3.5.0.jar%E2%80%99%2C%0A%E2%80%98lib%2Fjaudiotagger.jar%E2%80%99%2C%0A%E2%80%98lib%2Fjars%2Fh2-1.3.164.jar%E2%80%99%2C%0A%E2%80%98lib%2Fjars%2Fmessages.jar%E2%80%99%2C%0A%E2%80%98lib%2Fjars%2Fslf4j-api-1.7.5.jar%E2%80%99%2C%0A%E2%80%98lib%2Fjars%2Fjaudiotagger.jar%E2%80%99%2C%0A%E2%80%98lib%2Fjars%2Fmetadata-extractor-2.6.2.jar%E2%80%99%0A)%0A%7D\" message=\"\" highlight=\"\" provider=\"manual\"\/]","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3336,"url":"https:\/\/www.gubatron.com\/blog\/gradle-how-to-specify-resources-from-different-folders-on-your-sourceset\/","url_meta":{"origin":3331,"position":1},"title":"GRADLE: How to specify resources from different folders on your sourceSet","author":"gubatron","date":"July 29, 2014","format":false,"excerpt":"Sometimes you need to have resources in your sourceset and these may come from different locations on disk, the official documentation is lacking in real world examples, or at least I just didn't understand it very well, but from reading forums I finally got it to work. In the example\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3321,"url":"https:\/\/www.gubatron.com\/blog\/solved-gradle-how-to-increase-the-java-compilers-available-heap-memory\/","url_meta":{"origin":3331,"position":2},"title":"[SOLVED] Gradle: How to increase the Java Compiler&#8217;s available Heap Memory","author":"gubatron","date":"July 29, 2014","format":false,"excerpt":"The documentation is not very clear on what all the available options are... after much Googling and many different attempts finally figured out how to raise the maximum heap of the compiler from within the gradle.build script. [pastacode lang=\"java\" manual=\"apply%20plugin%3A%20%E2%80%98java%E2%80%99%0A%0AcompileJava%20%7B%0A%2F%2Fraise%20heap%0Aoptions.fork%20%3D%20%E2%80%98true%E2%80%99%0Aoptions.forkOptions.with%20%7B%0AmemoryMaximumSize%20%3D%20%E2%80%9C2048m%E2%80%9D%0A%7D%0A%7D\" message=\"\" highlight=\"\" provider=\"manual\"\/] Update: So I've noticed this works great\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3164,"url":"https:\/\/www.gubatron.com\/blog\/how-to-have-a-play-framework-app-autostart-during-boot-on-elastic-beanstalk-centos-ec2-instances\/","url_meta":{"origin":3331,"position":3},"title":"How to have a Play framework app autostart during boot on Elastic Beanstalk CentOS ec2 instances","author":"gubatron","date":"September 27, 2013","format":false,"excerpt":"So you've created an Elastic Beanstalk environment, you have a play framework distribution which you've created using play dist (either on your local environment, or right there on the server, whatever you prefer) play dist outputs a my-app-1.0.zip file which has a self-contained version of your app with all the\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3802,"url":"https:\/\/www.gubatron.com\/blog\/gradle-groovy-a-simple-way-to-check-if-a-gradle-task-name-has-been-invoked-e-g-assemblerelease-for-android-developers\/","url_meta":{"origin":3331,"position":4},"title":"gradle\/groovy: A simple way to check if a gradle task name has been invoked (e.g. &#8220;assembleRelease&#8221; for Android developers)","author":"gubatron","date":"May 4, 2019","format":false,"excerpt":"If you google for this question, you'll find a bunch of crap answers about creating tasks and checking the task graph, bullshit. All you need to do is check if a parameter has been passed to gradle. Keep it simple and stupid: [pastacode lang=\"java\" manual=\"boolean%20isAssembleRelease%20%3D%20gradle.startParameter.taskNames.contains(%22assembleRelease%22)\" message=\"\" highlight=\"\" provider=\"manual\"\/] (If you're\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2019\/05\/simple.jpg?fit=1000%2C667&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2019\/05\/simple.jpg?fit=1000%2C667&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2019\/05\/simple.jpg?fit=1000%2C667&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2019\/05\/simple.jpg?fit=1000%2C667&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":3388,"url":"https:\/\/www.gubatron.com\/blog\/how-to-create-a-list-that-holds-different-object-types-using-void-in-c\/","url_meta":{"origin":3331,"position":5},"title":"How to create a list that holds different object types using `void*` in C.","author":"gubatron","date":"April 5, 2015","format":false,"excerpt":"I remember being in school back around 1998 and not knowing enough about C to do this. After coding in other languages, then going back to C++ and understanding at a lower level how references and pointers work, this was pretty easy to figure out. In this exercise I store\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2015\/04\/Screen-Shot-2015-12-20-at-7.05.10-PM.png?fit=1200%2C438&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2015\/04\/Screen-Shot-2015-12-20-at-7.05.10-PM.png?fit=1200%2C438&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2015\/04\/Screen-Shot-2015-12-20-at-7.05.10-PM.png?fit=1200%2C438&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2015\/04\/Screen-Shot-2015-12-20-at-7.05.10-PM.png?fit=1200%2C438&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2015\/04\/Screen-Shot-2015-12-20-at-7.05.10-PM.png?fit=1200%2C438&ssl=1&resize=1050%2C600 3x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/3331","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/comments?post=3331"}],"version-history":[{"count":2,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/3331\/revisions"}],"predecessor-version":[{"id":3785,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/3331\/revisions\/3785"}],"wp:attachment":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/media?parent=3331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/categories?post=3331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/tags?post=3331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}