n00b
n00b

Reputation: 6360

Gradle error when creating a fat jar

I'm trying to create a fat jar using Gradle. I'm running into an error similar to this one raised against Gradle. Unfortunately I don't understand Gradle nor Groovy enough to come up with a creative workaround so I'm hoping someone here would be able to help. I've searched online for various workarounds to no avail :(

My particular conflict is with the Apache Storm dependency:

...
Caused by: org.gradle.api.GradleException: Could not copy zip entry /Users/DefaultUser/.gradle/caches/modules-2/files-2.1/org.apache.storm/storm-core/0.10.0-beta1/c3ba45e5ba616335c9f4be12317a8ebf2d2f17ba/storm-core-0.10.0-beta1.jar!META-INF/license/LICENSE.base64.txt to '/Users/DefaultUser/Projects/streams/build/tmp/expandedArchives/storm-core-0.10.0-beta1.jar_6i3o5dzb4lwfvasqr1cg4giqy/META-INF/license/LICENSE.base64.txt'.
    at org.gradle.api.internal.file.AbstractFileTreeElement.copyTo(AbstractFileTreeElement.java:79)
    at org.gradle.api.internal.file.archive.ZipFileTree$DetailsImpl.getFile(ZipFileTree.java:125)
    at org.gradle.api.internal.file.AbstractFileTree$1.visitFile(AbstractFileTree.java:39)
    at org.gradle.api.internal.file.AbstractFileTree$FilteredFileTree$1.visitFile(AbstractFileTree.java:145)
    at org.gradle.api.internal.file.archive.ZipFileTree.visit(ZipFileTree.java:90)
    ... 50 more
Caused by: org.gradle.api.UncheckedIOException: Cannot create directory '/Users/DefaultUser/Projects/streams/build/tmp/expandedArchives/storm-core-0.10.0-beta1.jar_6i3o5dzb4lwfvasqr1cg4giqy/META-INF/license' as it already exists, but is not a directory
    at org.gradle.util.GFileUtils.mkdirs(GFileUtils.java:261)
    at org.gradle.api.internal.file.AbstractFileTreeElement.copyTo(AbstractFileTreeElement.java:73)
    ... 54 more

My gradle code to create a fat jar is as follows:

jar {

    manifest {
        attributes 'Main-Class': mainClassName,
                'Implementation-Version': version
    }

    from {
        configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

Upvotes: 4

Views: 2023

Answers (2)

Anton Nikanorov
Anton Nikanorov

Reputation: 351

My build.gradle for build fat jar:

https://gist.github.com/Antowka/cab25f17cd704eaefdc8

Upvotes: 0

n00b
n00b

Reputation: 6360

After searching for a whole day looking for a workaround I found one 5 minutes after I posted my question...

This is not an ideal workaround as it excludes the license however I got it working via the following. If someone has a better solution I'd be very interested.

jar {

    from(configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }) {
        exclude "META-INF/*.SF"
        exclude "META-INF/LICENSE"
    }

    manifest {
        attributes 'Main-Class': mainClassName,
                'Implementation-Version': version
    }

}

Upvotes: 4

Related Questions