试图理解关于 gradle 样本的 "into" 闭包中的 "from"

trying to understand the "from" in the "into" closure about a gradle sample

在学习教程的过程中遇到了下面的例子:

task dist(type: Zip) {
    dependsOn spiJar
    from 'src/dist'
    into('libs') {
        from spiJar.archivePath    // what's meaning
        from configurations.runtime // what's meaning
    }
}

artifacts {
   archives dist
}

作为gradle的新手,如何理解这个into(...){ from ...}

在这种特殊情况下:

from spiJar.archivePath

可能(因为我不知道 spiJar 到底是什么)解析为 spiJar 任务的输出 - 即 jar 存档 - 特定文件。

当谈到第二个问题时,configurations 是(简化)是一个匹配给定名称的映射 - runtime 在这种情况下 - 具有一组依赖项(在这种情况下是 jar 文件) .

时间:

from configurations.runtime 

用于将所有依赖项从 runtime 配置复制到给定目标。

除了, to, possibly, clarify a little. Due to dsl referenceZip任务提供了into(destPath, configureClosure)方法,其中:

Creates and configures a child CopySpec with a destination directory inside the archive for the files.

这意味着,它可以创建一个附加目录,其中包含一些内容。在您的情况下,脚本在存档中创建一个 libs 目录并指定应复制到该目录中的资源。此资源可能不在 src/dist 目录中,该目录将完全压缩到存档的根目录中。

这里有一个dsl reference for CopySpec任务,通过Zip任务的into方法配置。如您所见,from 只是:

Specifies source files or directories for a copy.