开发者

Gradle Zip task to do multiple sub-trees?

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(ty开发者_开发知识库pe: Zip, dependsOn: jar) {
    from('build/libs/foo.jar').into('.')
    from('bar').into('bar')
}

Any help would be appreciated.

EDIT: Gradle 1.0-milestone-3


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.


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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜