首页 > 解决方案 > Gradle 任务:复制依赖项、重命名和取消归档

问题描述

我的要求是从 maven 下载 java 依赖项并将每个要提取的 jar 重命名并重命名为不同的名称。

task downloadOutput() { 
  doLast {
    def downloadsDir = "${buildDir}/output/"
    copy {
      from configurations.mydependencies
      rename { fileName -> filename + "-l2"
        
      }
      into file(downloadsDir)
    }
  }
}

添加from zipTree (configuration.mydependencies)也失败并出现以下错误。

Execution failed for task ':downloadOutput'.
> Cannot convert the provided notation to a File or URI: configuration ':mydependencies'.
  The following types/formats are supported:
    - A String or CharSequence path, for example 'src/main/java' or '/usr/include'.
    - A String or CharSequence URI, for example 'file:/usr/include'.
    - A File instance.
    - A Path instance.
    - A Directory instance.
    - A RegularFile instance.
    - A URI or URL instance.

如何修复这个 zipTree?有不同的方法或api吗?

标签: gradlegroovy

解决方案


推荐阅读