Gradle Zip DuplicatesStrategy not working correctly

余生长醉 提交于 2019-12-11 19:59:07

问题


Suppose you have something like:

task zip(type: Zip) {
  archiveName = "out.zip"
  duplicatesStrategy = 'exclude'

  into('TARGET_FOLDER_IN_ZIP') {
    from("$rootDir/customizations/folder1")
    from("$rootDir/customizations/folder2")
  }
}

According to http://www.gradle.org/docs/current/javadoc/org/gradle/api/file/DuplicatesStrategy.html Exclude means

Do not allow duplicates by ignoring subsequent items to be created at the same path.

So if you have the same filename in folder1 & folder2 only the file from folder1 should end up in the zip. If you change the two "from" lines in the buildfile, only the file from folder2 should end up there. This seems not to be whats happening (gradle 1.10). Instead always the same file is used. Seems like nested "from"s do not preserve their order.


回答1:


The only solution I've found is to split up the conflicting parts:

  into('TARGET_FOLDER_IN_ZIP') {
    from("$rootDir/customizations/folder1")
  }
  into('TARGET_FOLDER_IN_ZIP') {
    from("$rootDir/customizations/folder2")
  }

now the order is preserved and the output is deterministic



来源:https://stackoverflow.com/questions/26036879/gradle-zip-duplicatesstrategy-not-working-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!