Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pack a jar without dependency classes in gradle similar to maven

How to write a gradle script so that the application jar should be packed without dependency classes similar to maven jar package

like image 287
Pez Avatar asked Apr 07 '16 12:04

Pez


People also ask

How do you avoid transitive dependencies in Gradle?

Excluding a dependency from a configuration completely Similar to excluding a dependency in a dependency declaration, you can exclude a transitive dependency for a particular configuration completely by using Configuration. exclude(java. util. Map).

Is Gradle similar to Maven?

Both are able to cache dependencies locally and download them in parallel. As a library consumer, Maven allows one to override a dependency, but only by version. Gradle provides customizable dependency selection and substitution rules that can be declared once and handle unwanted dependencies project-wide.

Is Gradle dependent on Maven?

Gradle can consume dependencies available in the local Maven repository. Declaring this repository is beneficial for teams that publish to the local Maven repository with one project and consume the artifacts by Gradle in another project. Gradle stores resolved dependencies in its own cache.


2 Answers

The application JAR is always without dependencies, except you use special plugins to create a "fat" JAR where the dependencies are included. If you ask how to set up a Gradle build at all, you should start reading the Users Guide.

like image 195
Vampire Avatar answered Sep 26 '22 12:09

Vampire


If you are trying to package a jar from your Android app or library: I ran into this question because gradle would include 3rd party libraries into my jar when running gradle assembleRelease.

The contents of the jar then looked like this:

com/android/...
   /myCompany/...

For some reason this did not happen when building for debug. Finally I found that changing:

compile 'com.android.support:recyclerview-v7:23.0.0'

to

provided 'com.android.support:recyclerview-v7:23.0.0'

would not include the 3rd party libs ...

like image 21
electronix384128 Avatar answered Sep 23 '22 12:09

electronix384128