Duplicate classes in kotlin-runtime and com.intellij:annotations

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/annotations-cleaned.jar") { builtBy 'cleanAnnotationsJar' }
    cleanedAnnotations 'org.jetbrains:annotations:13.0'

task cleanAnnotationsJar(type:Jar) {
    configurations.cleanedAnnotations.each { f ->
        from zipTree(f)
    }
    archiveName = "annotations-cleaned.jar"
    exclude 'org/jetbrains/annotations/NotNull.class'
    exclude 'org/jetbrains/annotations/Nullable.class'
}