我怎样才能导入一个脚本摇篮到另一个? [英] How can I import one Gradle script into another?

查看:140
本文介绍了我怎样才能导入一个脚本摇篮到另一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有包装了的周围建筑功能的负载和部署了许多的netbeans项目与数的环境的复杂的gradle脚本

I have a complex gradle script that wraps up a load of functionality around building and deploying a number of netbeans projects to a number of environments.

该脚本的作品非常好,但它在本质上都是通过半打地图配置控股项目和环境的信息。

The script works very well, but in essence it is all configured through half a dozen maps holding project and environment information.

我要抽象的任务远到另一个文件,这样我可以简单地在一个简单的构建文件中定义我的地图,并从其他文件中导入的任务。这样一来,我可以使用相同的核心任务的一些项目和配置这些项目,一组简单的映射。

I want to abstract the tasks away into another file, so that I can simply define my maps in a simple build file, and import the tasks from the other file. In this way, I can use the same core tasks for a number of projects and configure those projects with a simple set of maps.

谁能告诉我怎样才能导入一个文件的gradle到另一个,以类似的方式到Ant的任务吗?我拖网摇篮的文档无济于事为止。

Can anyone tell me how I can import one gradle file into another, in a similar manner to Ant's task? I've trawled Gradle's docs to no avail so far.

其他信息

以下汤姆的回应后,我想我会尝试和澄清正是我的意思。

After Tom's response below, I thought I'd try and clarify exactly what I mean.

基本上我有它运行的一些子项目的脚本的Gradle。但是,子项目都Netbeans的项目,并配有自己的Ant构建脚本,所以我在gradle这个任务调用这些内容。

Basically I have a gradle script which runs a number of subprojects. However, the subprojects are all Netbeans projects, and come with their own ant build scripts, so I have tasks in gradle to call each of these.

我的问题是,我有一些配置在文件的顶部,如:

My problem is that I have some configuration at the top of the file, such as:

projects = [
    [name:"MySubproject1", shortname: "sub1", env:"mainEnv", cvs_module="mod1"],
    [name:"MySubproject2", shortname: "sub2", env:"altEnv", cvs_module="mod2"]
]

我然后生成的任务,例如:

I then generate tasks such as:

projects.each({
    task "checkout_$it.shortname" << {
         // Code to for example check module out from cvs using config from 'it'.
    }
})

我有很多这样的排序任务产生片断,而他们都是通用的 - 他们完全依赖于项目列表中的配置

I have many of these sort of task generation snippets, and all of them are generic - they entirely depend on the config in the projects list.

所以,我要的是把它放到一个单独的脚本,并在下面这种方式导入的方式:

So what I want is a way to put this in a separate script and import it in the following sort of way:

projects = [
    [name:"MySubproject1", shortname: "sub1", env:"mainEnv", cvs_module="mod1"],
    [name:"MySubproject2", shortname: "sub2", env:"altEnv", cvs_module="mod2"]
]

import("tasks.gradle") // This will import and run the script so that all tasks are generated for the projects given above.

因此​​,在这个例子中,tasks.gradle将所有的通用任务代$ C $在c和将获得运行在主的build.gradle文件中定义的项目。通过这种方式,tasks.gradle是可以通过包含若干个子项目,Netbeans的Ant构建文件的所有大型项目中使用的文件。

So in this example, tasks.gradle will have all the generic task generation code in, and will get run for the projects defined in the main build.gradle file. In this way, tasks.gradle is a file that can be used by all large projects that consist of a number of sub-projects with Netbeans ant build files.

推荐答案

该问题的答案竟然是在插件系统,在这里,你可以在一个插件集可以是位于常规文件添加所需的功能目录 buildSrc / src目录/主/常规。插件还可以捆绑为一个瓶子,虽然我还没有尝试过这一点。

The answer to the question turned out to be in the Plugins system, where you can add the desired functionality in a set of plugins which can be groovy files located in the directory buildSrc/src/main/groovy. Plugins can also be bundled as a Jar though I haven't tried this.

详情点击此处:<一href=\"http://www.gradle.org/docs/current/userguide/userguide_single.html#sec%3aconfiguring_using_external_script\">Custom插件

这篇关于我怎样才能导入一个脚本摇篮到另一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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