In gradle - how can I embed jars inside my build output jar in the lib directory (specifially the lib/enttoolkit.jar and lib/mail.jar)?
Gradle declares dependencies on JAR files inside your project's module_name /libs/ directory (because Gradle reads paths relative to the build.gradle file). This declares a dependency on version 12.3 of the "app-magic" library, inside the "com.example.android" namespace group.
In its simplest form, creating an executable JAR with Gradle is just a matter of adding the appropriate entries to the manifest. However, it's much more common to have dependencies that need to be included on the classpath, making this approach tricky in practice.
If you have all the jars inside a directory (lets call it libs
) in your project, you only need this:
jar { into('lib') { from 'libs' } }
I guess it is more likely that these jars are dependencies of some sort. Then you could do it like this:
configurations { // configuration that holds jars to copy into lib extraLibs } dependencies { extraLibs 'org.something:something-dep1:version' extraLibs 'org.something:something-dep2:version' } jar { into('lib') { from configurations.extraLibs } }
Lifted verbatim from: http://docs.codehaus.org/display/GRADLE/Cookbook#Cookbook-Creatingafatjar
Gradle 0.9:
jar { from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
Gradle 0.8:
jar.doFirst { for(file in configurations.compile) { jar.merge(file) } }
The above snippets will only include the compile dependencies for that project, not any transitive runtime dependencies. If you also want to merge those, replace configurations.compile with configurations.runtime.
EDIT: only choosing jars you need
Make a new configuration, releaseJars maybe
configurations { releaseJars }
Add the jars you want to that configuration
dependencies { releaseJars group: 'javax.mail', name: 'mail', version: '1.4' //etc }
then use that configuration in the jar task outlined above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With