# Kotlin gradle.build ZipException because of duplicates

**URL:** <https://discuss.kotlinlang.org/t/kotlin-gradle-build-zipexception-because-of-duplicates/2133>\
**Category:** Android\
**Created:** [December 1, 2016, 8:54pm UTC](https://discuss.kotlinlang.org/t/kotlin-gradle-build-zipexception-because-of-duplicates/2133 "2016-12-01T20:54:58Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexander-fischer](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@alexander-fischer](https://discuss.kotlinlang.org/u/alexander-fischer)\
**Post date:** [December 1, 2016, 8:54pm UTC](https://discuss.kotlinlang.org/t/kotlin-gradle-build-zipexception-because-of-duplicates/2133/1 "2016-12-01T20:54:58Z")

</div>

I add Kotlin to the gradle.build with dependency (Kotlin version 1.0.4):

```
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

```

As I found out it has a conflict with my other dependency:

```
compile 'org.jetbrains:annotations-java5:15.0'

```

After I run the build it crashes with the ZipException:

```
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/jetbrains/annotations/Nullable.class

```

**What I already tried:**

I tried this solution:

> <https://stackoverflow.com/questions/39660420/kotlin-java-multidex-dagger-2-butterknife-and-realm-transformclasseswithjarmerg/39660615#39660615>

But it ended up, that not only _Nullable.class_ and _NotNull.class_ were duplicates, but also classes from _org/intellij/lang/annotations/_.

After I added five classes it still crashed. Is there a better way to get rid of this problem, by not adding every class manually that causes this exception?

**UPDATE (02.02.16)**

As I worked a bit on the problem, I found out that for my project the relevant annotation classes are `NonNls.class` and `Contract.class` that are missing, if I remove `org.jetbrains:annotations-java5:15.0`. They are not in kotlin-runtime, but in the Jetbrains annotation dependency. How can I add it without adding the Jetbrains annotation dependency again? Or what about adding the whole library to Kotlin?

---

<div class="post-metadata">

**Author:** ![pdvrieze](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/pdvrieze/32/1882_2.png) [@pdvrieze](https://discuss.kotlinlang.org/u/pdvrieze)\
**Post date:** [December 1, 2016, 10:30pm UTC](https://discuss.kotlinlang.org/t/kotlin-gradle-build-zipexception-because-of-duplicates/2133/2 "2016-12-01T22:30:38Z")

</div>

Take a look at my reply half a year ago. That is in an android context, but there is nothing android-specific to the solution:

> [@Duplicate classes in kotlin-runtime and com.intellij:annotations](https://discuss.kotlinlang.org/t/duplicate-classes-in-kotlin-runtime-and-com-intellij-annotations/154/3):
>
> While exclusion is “nice”, we can do better. I’ve added the following snippets to my build file to handle it better (Other annotations in the annotation package are used as well). Basically, the excluded annotations library is replaced by a file dependency on a jar file that automatically has the offending classes stripped out. configurations { cleanedAnnotations compile.exclude group: 'org.jetbrains' , module:'annotations' } … dependencies { compile files("${buildDir}/libs/anno…

I see, that is where the stackoverflow answer comes from as well. The amount of classes should be fairly limited so I would stick with manually enumerating them. Of course you could configure gradle with a filter (instead of manual exclusions) and in that filter check for containment of the name in kotlin-stdlib → better yet, cache this somehow as it’s not really fast.

---

<div class="post-metadata">

**Author:** ![ilya.gorbunov](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/ilya.gorbunov/32/1645_2.png) [@ilya.gorbunov](https://discuss.kotlinlang.org/u/ilya.gorbunov)\
**Post date:** [December 1, 2016, 11:19pm UTC](https://discuss.kotlinlang.org/t/kotlin-gradle-build-zipexception-because-of-duplicates/2133/3 "2016-12-01T23:19:32Z")

</div>

Could you be more explicit, what other classes in particular are duplicates (except `Nullable`, `NotNull`, `Mutable` and `ReadOnly`)?

---

<div class="post-metadata">

**Author:** ![alexander-fischer](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@alexander-fischer](https://discuss.kotlinlang.org/u/alexander-fischer)\
**Post date:** [December 2, 2016, 9:23am UTC](https://discuss.kotlinlang.org/t/kotlin-gradle-build-zipexception-because-of-duplicates/2133/4 "2016-12-02T09:23:36Z")

</div>

Other classes are for example `Flow.class` or `Identifier.class`.

---

<div class="post-metadata">

**Author:** ![ilya.gorbunov](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/ilya.gorbunov/32/1645_2.png) [@ilya.gorbunov](https://discuss.kotlinlang.org/u/ilya.gorbunov)\
**Post date:** [December 2, 2016, 8:41pm UTC](https://discuss.kotlinlang.org/t/kotlin-gradle-build-zipexception-because-of-duplicates/2133/5 "2016-12-02T20:41:52Z")

</div>

You should examine from which dependencies these two annotation classes are coming from, because `kotlin-runtime` bundles only those 4 annotations, and neither `Flow` nor `Identifier` are in that list.

Most likely the conflict is between `'org.jetbrains:annotations-java5:15.0'` and `'org.jetbrains:annotations:15.0'`.

You can use `dependenies` gradle task to inspect the dependency graph of your project.

---

<div class="post-metadata">

**Author:** ![alexander-fischer](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@alexander-fischer](https://discuss.kotlinlang.org/u/alexander-fischer)\
**Post date:** [December 5, 2016, 1:05pm UTC](https://discuss.kotlinlang.org/t/kotlin-gradle-build-zipexception-because-of-duplicates/2133/6 "2016-12-05T13:05:57Z")

</div>

Thanks for your answer. I only have `'org.jetbrains:annotations-java5:15.0'` as a dependency and not the other one. I updated my question, because I’m at the point to drop the whole dependency.

---

<div class="post-metadata">

**Author:** ![praveenpro](https://avatars.discourse-cdn.com/v4/letter/p/8e7dd6/32.png) [@praveenpro](https://discuss.kotlinlang.org/u/praveenpro)\
**Post date:** [February 6, 2018, 5:17am UTC](https://discuss.kotlinlang.org/t/kotlin-gradle-build-zipexception-because-of-duplicates/2133/7 "2018-02-06T05:17:42Z")

</div>

Hey @ilya.gorbunov I’m having the build error

```
Error:Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
> java.io.IOException: Can't write [/home/imedrix-server/StudioProjects/kardioscreen-operatorapp/app/build/intermediates/multi-dex/debug/componentClasses.jar] (Can't read [/home/imedrix-server/StudioProjects/kardioscreen-operatorapp/app/build/intermediates/transforms/desugar/debug/76.jar(;;;;;;**.class)] (Duplicate zip entry [76.jar:org/intellij/lang/annotations/Flow.class])) 

```

I added kotlin library  
`implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"`

to the existing Android Java project then only I’m getting the error. If I remove there is no error.

Please help me to solve the issue.

---

<div class="post-metadata">

**Author:** ![ilya.gorbunov](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/ilya.gorbunov/32/1645_2.png) [@ilya.gorbunov](https://discuss.kotlinlang.org/u/ilya.gorbunov)\
**Post date:** [February 7, 2018, 8:08am UTC](https://discuss.kotlinlang.org/t/kotlin-gradle-build-zipexception-because-of-duplicates/2133/8 "2018-02-07T08:08:54Z")

</div>

@praveenpro It looks like you have class `org.intellij.lang.annotations.Flow` coming from several jars. One of them is coming from `org.jetbrains:annotations` maven artifact which is a transitive dependency of `org.jetbrains.kotlin:kotlin-stdlib-jre7` and to find the other, you can run `gradlew dependency` to show the dependency graph of your project.  
Then you may want to exclude one of the conflicting artifacts: [java - How do I exclude all instances of a transitive dependency when using Gradle? - Stack Overflow](https://stackoverflow.com/questions/21764128/how-do-i-exclude-all-instances-of-a-transitive-dependency-when-using-gradle)

---

<div class="post-metadata">

**Author:** ![praveenpro](https://avatars.discourse-cdn.com/v4/letter/p/8e7dd6/32.png) [@praveenpro](https://discuss.kotlinlang.org/u/praveenpro)\
**Post date:** [February 7, 2018, 9:43am UTC](https://discuss.kotlinlang.org/t/kotlin-gradle-build-zipexception-because-of-duplicates/2133/9 "2018-02-07T09:43:47Z")

</div>

Thanks a lot @ilya.gorbunov The issue is solved by adding the line

```
configurations {
        compile.exclude group : 'org.jetbrains' , module : 'annotations'
    }

```
