Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiproject gradle duplicate dependencies in distribution ZIP

I have a gradle multi-project setup for which I wish to collect all the dependent and output JARs into a ZIP at the top level. I've got something working, however I end up with duplicates in the ZIP file. I've not found anything useful in the official documentation on multi project setups

  • How can I remove the duplicates?
  • Is there another approach I should take?

Structure

./multi-project
./multi-project/build.gradle
./multi-project/settings.gradle
./multi-project/bar
./multi-project/bar/build.gradle
./multi-project/foo
./multi-project/foo/build.gradle

Top level build.gradle

apply plugin: 'java'

allprojects {
  apply plugin: 'java'

  repositories {
    mavenCentral()
  }
}

task buildDist(type: Zip) {
    from subprojects.configurations.compile into 'jars'
    from subprojects.jar.outputs.files into 'jars'
}

Settings.gradle

include ':foo'
include ':bar'

Lower level build.gradle files for foo and bar (both same)

dependencies {
   compile 'org.springframework:spring-beans:4.1.0.RELEASE'
}

When I run gradle :buildDist from the top level the ZIP has duplicates

unzip -l build/distributions/multi-project.zip 

Archive:  build/distributions/multi-project.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2014-09-09 20:17   jars/
   701334  2014-09-09 19:53   jars/spring-beans-4.1.0.RELEASE.jar
    62050  2014-07-05 21:09   jars/commons-logging-1.1.3.jar
  1005039  2014-09-09 19:53   jars/spring-core-4.1.0.RELEASE.jar
   701334  2014-09-09 19:53   jars/spring-beans-4.1.0.RELEASE.jar
    62050  2014-07-05 21:09   jars/commons-logging-1.1.3.jar
  1005039  2014-09-09 19:53   jars/spring-core-4.1.0.RELEASE.jar
      301  2014-09-09 20:12   jars/bar.jar
      301  2014-09-09 20:12   jars/foo.jar
like image 586
Adam Avatar asked Sep 09 '14 19:09

Adam


1 Answers

task buildDist(type: Zip) {
    into 'jars'
    from { subprojects.configurations.runtime }
    from { subprojects.jar }
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

To see all configuration options for a particular Gradle task type, consult the Gradle Build Language Reference.

like image 163
Peter Niederwieser Avatar answered Oct 16 '22 03:10

Peter Niederwieser