Gradle Zip 任务做多个子树?

发布于 2024-11-08 03:10:49 字数 526 浏览 3 评论 0原文

我们试图在 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

We're trying to build up a minorly complicated Zip file in Gradle from multiple filesystem source trees, but no matter how many into specifications we give, it all puts them in the same one. Is this possible to do in 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

¢蛋碎的人ぎ生 2024-11-15 03:10:49

试试这个:

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

首先... jar 应该位于 zip 的 root / 中(这似乎就是您想要的)。其次,通过指定 from jar.outputs.files,jar 任务上有一个隐式的 dependsOn,因此这显示了完成您想要的任务的另一种方法。除非使用这种方法,如果 jar 名称随着时间的推移而改变,那并不重要。如果您需要其他帮助,请告诉我。

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.

清晰传感 2024-11-15 03:10:49

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

}

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

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):

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.

梦里寻她 2024-11-15 03:10:49

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

    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);

This answer does not directly answer the question but I guess this would help someone who writes '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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文