17

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

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

我们得到了这个:

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

使用这个:

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

任何帮助,将不胜感激。

编辑:Gradle 1.0-milestone-3

4

3 回答 3

26

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 dependsOn on 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.

于 2011-05-16T19:44:33.267 回答
10

显然,对答案的评论不允许以方便的方式显示更多代码......或者这并不明显:)我有一个针对客户的项目......所以我无法分享完整的项目/构建文件。这是我可以分享的内容(我将项目特定的 acron 更改为 XXX):

任务邮编(类型:邮编){

    来自 jar.outputs.files

    从('脚本/'){
        文件模式 = 0755
        包括'**/runXXX.sh'
        包括'**/runXXX.bat'
    }
    来自('lib/'){
        包括'**/*.jar'
        进入('lib')
    }
    从('。') {
        包括“xxx.config”
    }

}

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

于 2011-05-17T19:19:44.853 回答
0

这个答案没有直接回答这个问题,但我想这会对编写“Gradle Plugins”的人有所帮助

    final Zip zipTask = project.getTasks().create(taskName, Zip.class);
    
    final Action<? super CopySpec> cp1 = (p) -> {
        p.include("**/Install_*.xml", "**/Install.xml").into(WORKING_DIR_1);
    };
    final Action<? super CopySpec> cp2 = (p) -> {
        p.include("*Terminology*.xml").into(WORKING_DIR_2);
    };
    zipTask.from(projectDir + "/Release", cp1);
    zipTask.from(projectDir + "/Release", cp2);
于 2020-07-15T04:34:42.037 回答