Search code examples
javaamazon-web-servicesgradlejavafxmeta-inf

JavaFX Gradle build error, java.util.zip.ZipException: duplicate entry: META-INF/LICENSE


I'm using Gradle to build a JavaFX application. The problem I keep running into is a "duplicate entry" error for META-INF/LICENSE.

My jar includes a dependency on the Amazon AWS SDK, so I'm assuming the error is generated from that. To this point, I've found a solution as described here:

Duplicate Zip Entry after Gradle Plugin v0.13.1

which describes my exact problem, but only in the context of Android Gradle.

Specifically, the solution was:

android.packagingOptions {
    pickFirst 'META-INF/LICENSE.txt'
}

Of course, such an option is noticeably absent in Gradle. My question: Is there a straightforward way to address this issue in the build code rather than having to manually look for and remove duplicate META-INF/LICENSE occurrences?

For completeness, here's the error gradle assemble generates:

Caused by: java.util.zip.ZipException: duplicate entry: META-INF/LICENSE
    at com.sun.javafx.tools.packager.PackagerLib.copyFromOtherJar(PackagerLib.java:1409)
    at com.sun.javafx.tools.packager.PackagerLib.jar(PackagerLib.java:1366)
    at com.sun.javafx.tools.packager.PackagerLib.packageAsJar(PackagerLib.java:288)
    ... 54 more

And my gradle.build script:

apply from: 'javafx.plugin'

repositories {
    mavenCentral()
}

dependencies {
    compile ('com.amazonaws:aws-java-sdk:1.9.13') {
        exclude group: 'commons-io', module: 'commons-io'
    }
    testCompile group: 'junit', name: 'junit', version: '4.+'
}

jar  {
   from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
   manifest {
      attributes 'Main-Class': 'com.buddyware.treefrog.Main'
   }
}

Solution

  • Based on Mark Vieira's suggestion and a little digging for live examples, I modified my build.gradle file's jar task to read as follows:

    jar  {
       duplicatesStrategy(DuplicatesStrategy.EXCLUDE)
       from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
       manifest {
          attributes 'Main-Class': 'com.buddyware.treefrog.Main'
       }
    }
    

    Running 'gradle assemble' succeeded without a complaint!