# Gradle and Shadow Jar

**URL:** <https://discuss.gradle.org/t/gradle-and-shadow-jar/19532>\
**Category:** Help/Discuss\
**Tags:** plugins\
**Created:** [September 14, 2016, 12:54pm UTC](https://discuss.gradle.org/t/gradle-and-shadow-jar/19532 "2016-09-14T12:54:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![imochurad](https://avatars.discourse-cdn.com/v4/letter/i/ecae2f/32.png) [@imochurad](https://discuss.gradle.org/u/imochurad)\
**Post date:** [September 14, 2016, 12:54pm UTC](https://discuss.gradle.org/t/gradle-and-shadow-jar/19532/1 "2016-09-14T12:54:36Z")

</div>

I am new to Gradle and ShadowJar. I am building an api project that is internally using a dropwizard framework. It’s a Java project. There are a bunch of dependencies that have same files under `META-INF/services/`. When my application loads it fails to properly configure one of the auto-discoverable services and fails miserably. I learned that shadowJar can be of help in this situation. Now I’m struggling to make some sense out of how it can be integrated. Here is what I have in my `build.gradle` file:

```
jar {
    zip64 true
    from { configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } }
    manifest {
        attributes(
        'Main-Class': mainClassName,
        'version': project.version,
        'lastBuild': buildTime()
        )
    }
}

    shadowJar {
        mergeServiceFiles()
    }

```

I build my project in the console by specifying: `./gradlew assemble`  
As the gradle outputs info while building, it doesn’t indicate invoking of the `shadowJar` task. It shows calling `jar` task, and I’d like `assemble` to invoke `shadowJar`.  
When I invoke `./gradlew shadowJar` it builds a fat shadowed jar with merged service files (however, this process also merges other duplicates, such as `META-INF/LICENSE.txt` and `javax/annotation/CheckForNull.class`. In the original fat jar I see multiple instances of these classes, whereas in the shadowed jar there is only one instance per unique class. I do not know if this is normal defaulted behaviour or not).  
Question: Is there a way to invoke `shadowJar` task automatically when running `assemble`? And what should be done for it?

---

<div class="post-metadata">

**Author:** ![vermeulen\_mp](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vermeulen_mp/32/5257_2.png) [@vermeulen\_mp](https://discuss.gradle.org/u/vermeulen_mp)\
**Post date:** [September 15, 2016, 8:22am UTC](https://discuss.gradle.org/t/gradle-and-shadow-jar/19532/2 "2016-09-15T08:22:31Z")

</div>

Hi @imochurad,

This plugin is not maintained by Gradle and is provided by [John Engelman](https://github.com/johnrengelman). I suggest that the first place to look would be on the plugin’s [Github Page](https://github.com/johnrengelman/shadow). The plugin has a very comprehensive [user guide](http://imperceptiblethoughts.com/shadow/) which explains all the details about how to use it, as well as it’s expected behaviour.

Regarding the final question, you can simply add the following line to your build script to make the assemble task depend on shadowJar:

```
assemble.dependsOn shadowJar

```

Hope this helps!

---

<div class="post-metadata">

**Author:** ![imochurad](https://avatars.discourse-cdn.com/v4/letter/i/ecae2f/32.png) [@imochurad](https://discuss.gradle.org/u/imochurad)\
**Post date:** [September 15, 2016, 12:38pm UTC](https://discuss.gradle.org/t/gradle-and-shadow-jar/19532/3 "2016-09-15T12:38:22Z")

</div>

Thanks for your reply. Yes, I have touch based with the author on the GitHub page, got my answer.  
In order to use `shadowJar` task instead of `jar`, I had to disable `jar` task by setting enabled to `false` and introducing `dependsOn` to `assemble`.  
This thread can be closed.

---

<div class="post-metadata">

**Author:** ![vermeulen\_mp](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vermeulen_mp/32/5257_2.png) [@vermeulen\_mp](https://discuss.gradle.org/u/vermeulen_mp)\
**Post date:** [September 15, 2016, 1:32pm UTC](https://discuss.gradle.org/t/gradle-and-shadow-jar/19532/4 "2016-09-15T13:32:34Z")

</div>


