Multiproject gradle duplicate dependencies in distribution ZIP

时间秒杀一切 提交于 2019-12-05 17:36:36
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.

This is best I've come up with

  • resolve all dependencies to File instances and drop into a HashSet.
  • Wrap in a gradle.taskGraph.whenReady closure otherwise the premature resolution causes the configuration to be locked when they try to add a dependency closure.

Example

task buildDist(type: Zip) {
    gradle.taskGraph.whenReady { taskGraph ->
      def uniqueFiles = new HashSet()

      uniqueFiles.addAll(subprojects.configurations.compile.resolvedConfiguration.resolvedArtifacts.file)
      uniqueFiles.addAll(subprojects.jar.outputs.files)

      from uniqueFiles into 'jars'

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