English 中文(简体)
逐步进入建筑 Dir
原标题:Gradle explode a zip into a buildDir
  • 时间:2011-11-21 16:46:03
  •  标签:
  • gradle

我的项目有很远的受扶养人,这确实只是某些卷宗的zi,有些地方需要解冻,因此建筑能够从卷宗中产生新的 j。 (一般而言,以核心问题而不是具体事项为重)

我不期望这一点如此困难,但我无法工作。 这里我所说的话:

我确定了一个新的配置:

configurations {
    newConf
}

后来,我就这一假想确定了单一依赖。 它解决I号案需要探讨:

dependencies {
    newConf "group:name:version@zip"
}

So far this all smells correct to me, though if anybody disagrees, I m listening.

最后,我需要确定一项任务,把烟火推入名录,然后成为后来的代号指挥的投入。

task explodeModel {
    description = "unzip model into the specified  modelSrc  directory"

    //input is a "files" collection (usually just one:  the zip)
    //output is the specified modelSrc dir

    File modelSrc = new File("$buildDir/modelSrc")
    outputs.files modelSrc

    doLast {
        configurations.newConf.allArtifacts.each { artifact -> println artifact }
    }

}

明显的做法 最后,我只想走一条绝对的道路,走到我 st的地处。 我对如何找到档案的道路没有任何看法,因此我可以 un。 任何帮助?

Many thanks

最佳回答

我在我所写的画面中做了类似的事情。 你们应当努力:

configurations.newConf.singleFile

The assumption is that there s only one file. The return type is java.io.File. For more information check this class GaePlugin.groovy. The method of relevance is configureDownloadSdk. The task that does the unzip is GaeDownloadSdkTask.groovy.

问题回答

为此,它应当努力:

task explodeModel(type: Copy){
  configurations.newConf.filter { it.toString().endsWith(".zip") }.each{
    from zipTree(it)
  }
  into  output/dir 
}

当然,如果你确信组合中的手法是假的,你可以忽略<条码>。

Here s what I ve been doing lately, and I ve been happy with it:
(This example assumes a configuration called zipFiles that includes only ZIP files.)

ext.unpackedZipFiles = fileTree("$buildDir/unpackedZipFiles") { builtBy  unpackZipFiles  }
task unpackZipFiles(type: Copy) {
    from configurations.zipFiles.files.collect { zipTree(it) }
    into unpackedZipFiles.dir
}

Details

有几个方面 我赞成这种做法:

  1. 在整个建筑中,没有安装“磁丝网”(<条码>)“泡沫/未包装的ZipFiles”()。 fileTree。 这使得在未来类似复制的工作中使用产出非常简单:

    aCopyLikeTask(type: Copy) {
        from unpackedZipFiles
        // ...
    }
    
  2. 使用未使用档案的任务并不直接取决于对档案进行清点的任务。 相反,它们取决于<代码>FileTree本身,后者知道如何整理档案。 注:<代码>FileTree > ,Buildable,因此可以依赖一项任务:

    aNonCopyTask(dependsOn: unpackedZipFiles) << {
        // ... do stuff that references unpackedZipFiles.dir
    }
    
  3. Project.fileTree() actually returns a ConfigurableFileTree, which is why we can specify one or more tasks that it is built by. This interface also provides the File of the root of the tree via the dir property, which is often handy. For example:

    myExecTask(dependsOn: unpackedZipFiles) << {
        "${unpackedZipFiles.dir}/bin/runMe".execute([], unpackedZipFiles.dir)
    }
    

My solution (adapted to our code) would be something along the lines of

task explodeModel(type: Copy) {
    configurations.newConf.resolvedConfiguration.resolvedArtifacts.each { artifact ->
        if (artifact.file.name.endsWith( .zip )) {
            from zipTree(artifact.file)
            into  . 
        }
    }
}

这一解决办法的好处是它反对resolved。 (而不是requested) artifacts。





相关问题
Some error characters appear during the gradle javadoc task

Some error characters appear during the gradle javaDoc build Gradle version 7.1 and I am using windows I tried to change the project encoding to utf-8 and added the idea vm parameter -Dfile.encoding=...

What are real-world examples of Gradle s dependency graph?

As noted in the documentation, Gradle uses a directed acyclic graph (DAG) to build a dependency graph. From my understanding, having separate cycles for evaluation and execution is a major feature for ...

How can I import one Gradle script into another?

I have a complex Gradle script that wraps up a load of functionality around building and deploying a number of NetBeans projects to a number of environments. The script works very well, but in essence ...

热门标签