如何使用Gradle生成源代码的ZIP? [英] How do I produce a ZIP of my source using Gradle?

查看:248
本文介绍了如何使用Gradle生成源代码的ZIP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将一个相对较小的项目从Ant转换为Gradle。我希望将构建脚本中的行数减少大约75%!



Ant构建的一件事就是生成一个源ZIP(即ZIP整个项目,删除了某些部分 - ./build,各种Eclipse文件夹等)。在将其迁移到Gradle时,我决定使用包容性方法,而不是独占方式,以免包含内容后来发生意外。

我希望能够获取所有源代码集的源代码和资源,而不必明确列出目录,但我不能运作。



这是我到目前为止(甚至没有运行!):

 任务srcZip(类型:Zip){
classifier ='src'
from projectDir
include {
sourceSets.collect {
it.allSource.asPath
}
}
}

ZIP文件应该以文件夹的src / main / j结尾ava / ...','src / main / resources / ...','src / test / java / ...'等,当我添加更多内容时,我不需要重新访问此任务来源集稍后。



预先感谢!

解决方案

将所有源代码放入1个zip文件中,您可以使用这个:

 任务srcZip(类型:Zip){
classifier = 'src'
from sourceSets * .allSource
}

它不会给你所要求的目录结构。来自所有源集的文件被放入同一层次结构。



为了得到你要求的东西,你可以使用这个:

 任务srcZip2(类型:Zip){
classifier ='src'
from projectDir
include'src / ** / *'
}

当然,它没有考虑到您可能对源代码所做的任何更改目录位置。


I'm converting a relatively small project from Ant to Gradle. I expect to reduce the number of lines in the build script by approximately 75%!

One thing the Ant build does is to produce a source ZIP (i.e. a ZIP of the whole project, with certain bits removed - ./build, various Eclipse folders, etc.) Whilst migrating this to Gradle, I decided to use an "inclusive" approach, rather than an "exclusive" approach so that things don't get included by accident later on.

I'd like to be able to grab the source code and resources for all of the source sets without having to list the directories explicitly, but I can't get it working.

Here's what I have so far (doesn't even run!):

task srcZip(type: Zip) {
    classifier = 'src'
    from projectDir
    include {
        sourceSets.collect {
            it.allSource.asPath
        }
    }
}

The ZIP file should end up with folders 'src/main/java/...', 'src/main/resources/...', 'src/test/java/...', etc., and I shouldn't need to re-visit this task when I add more source sets later on.

Thanks in advance!

解决方案

To get all sources into 1 zip file you can use this:

task srcZip(type: Zip) {
    classifier = 'src'
    from sourceSets*.allSource
}

It won't give you the directory structure you asked for though. The files from all source sets are put into the same hierarchy.

To get what you asked for you can use this:

task srcZip2(type: Zip) {
    classifier = 'src'
    from projectDir
    include 'src/**/*'
}

Of course, it doesn't take into account any changes you might make to source directory locations.

这篇关于如何使用Gradle生成源代码的ZIP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆