Search code examples
gradleandroid-gradle-pluginbuild.gradle

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


When learning from the tutorial, I encountered a sample below:

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
}

As a newbie to gradle, how to understand this into(...){ from ...}?


Solution

  • In addition to the previous answer, to, possibly, clarify a little. Due to dsl reference, Zip task provide the into(destPath, configureClosure) method, which:

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

    This means, that it could create an additional directory with the some content in it. In your case, script creates a libs directory within archive and specifies the resources, which should be copied into this directory. This resources could be out of the src/dist directory, which will be fully zipped into the archive's root.

    Here is a dsl reference for CopySpec task, which is configured by the into method of the Zip task. As you can see, from just:

    Specifies source files or directories for a copy.