Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Groovy Ant任务中保留原始文件名_Ant_Groovy - Fatal编程技术网

在Groovy Ant任务中保留原始文件名

在Groovy Ant任务中保留原始文件名,ant,groovy,Ant,Groovy,我有以下代码: new AntBuilder().zip( destFile: "${file}.zip" ) { fileset( dir: srcDir ) { include( name:pattern ) } } 在本例中,我希望ant使用与原始文件相同的名称创建一个zip,但在末尾添加一个.zip。在ant中有没有一种方法可以在不提前知道原始文件名称的情况下执行此操作?我也希望能够对其他ant任务做同样的事情 换言之,我

我有以下代码:

new AntBuilder().zip( destFile: "${file}.zip" ) {
        fileset( dir: srcDir ) {
            include( name:pattern )
        }
    }
在本例中,我希望ant使用与原始文件相同的名称创建一个zip,但在末尾添加一个.zip。在ant中有没有一种方法可以在不提前知道原始文件名称的情况下执行此操作?我也希望能够对其他ant任务做同样的事情

换言之,我希望文件名成为每个文件的“模式”

<target name="zip-files">
    <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>

    <dirset id="dirsToZip" dir="src">
        <include name="dir*"/>
    </dirset>

    <groovy>
        project.references.dirsToZip.each { 
            ant.zip(destfile: "${it}.zip", basedir: it)
        }
    </groovy>
</target>

project.references.dirsToZip.each{
ant.zip(destfile:“${it}.zip”,basedir:it)
}

如果发现groovy任务通过文件集或目录集进行迭代的能力,这是一个非常有用的特性。

什么类是“作业”对象?groovy zip任务接受字符串作为参数。我的错误是,这只是一个容器,包含它使问题变得复杂。我已经编辑好了。当你说Groovy Zip任务时…这是一个Ant的东西还是一个Groovy的东西?我该怎么做?好的,你是说唯一的方法是迭代所有的,没有声明性的方法。谢谢你的帮助!