java Gradle Zip 任务来做多个子树?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6022280/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 14:00:37  来源:igfitidea点击:

Gradle Zip task to do multiple sub-trees?

javazipgradle

提问by Alan Krueger

We're trying to build up a minorly complicated Zip file in Gradle from multiple filesystem source trees, but no matter how many intospecifications we give, it all puts them in the same one. Is this possible to do in Gradle?

我们试图在 Gradle 中从多个文件系统源树构建一个稍微复杂的 Zip 文件,但无论into我们给出多少规范,它们都将它们放在同一个中。这可以在 Gradle 中做到吗?

build/libs/foo.jar --> foo.jar
bar/*              --> bar/*

We're getting this instead:

我们得到了这个:

build/libs/foo.jar --> bar/foo.jar
bar/*              --> bar/*

Using this:

使用这个:

task installZip(type: Zip, dependsOn: jar) {
    from('build/libs/foo.jar').into('.')
    from('bar').into('bar')
}

Any help would be appreciated.

任何帮助,将不胜感激。

EDIT: Gradle 1.0-milestone-3

编辑:Gradle 1.0-milestone-3

回答by kensipe

Try this:

试试这个:

task zip(type: Zip) {
    from jar.outputs.files
    from('bar/') {
        into('bar')
    }
}

First... the jar should be in the root / of the zip (which seems to be what you want). Second, by specifying the from jar.outputs.files, there is an implicit dependsOnon the jar task, so this shows another way of accomplishing what you want. Except with this approach if the jar name changes over time it doesn't matter. Let me know if you need additional help.

首先...... jar 应该在 zip 的根 / (这似乎是你想要的)。其次,通过指定 from jar.outputs.filesdependsOn在 jar 任务中有一个隐式,所以这显示了完成你想要的另一种方式。除了这种方法,如果 jar 名称随时间变化,则无关紧要。如果您需要其他帮助,请告诉我。

回答by kensipe

Apparently the comments to an answer will not allow for a convenient way to show more code... or it isn't obvious :) I have a project which is for a client... so I can't share the full project / build file. Here is what I can share (I changed the project specific acron to XXX):

显然,对答案的评论不允许以方便的方式显示更多代码......构建文件。这是我可以分享的内容(我将项目特定的 acro 更改为 XXX):

task zip(type: Zip) {

    from jar.outputs.files

    from('scripts/') {
        fileMode = 0755
        include '**/runXXX.sh'
        include '**/runXXX.bat'
    }
    from('lib/') {
        include '**/*.jar'
        into('lib')
    }
    from('.') {
        include 'xxx.config'
    }

}

This creates a zip with the project jar in the root of the zip. Copies the scripts from a directory to the root, copies the config file to the root and creates a directory in the root of the zip named /lib and copies all the jars from the project /lib to the zip/lib.

这会在 zip 的根目录中创建一个包含项目 jar 的 zip。将脚本从目录复制到根目录,将配置文件复制到根目录,并在 zip 的根目录中创建一个名为 /lib 的目录,并将项目 /lib 中的所有 jar 文件复制到 zip/lib。