codecamp

Gradle 定位 tasks

定位 tasks

你经常需要定位你定义的 tasks, 举个例子, 为了配置它们或者使用它们作为依赖. 有许多种方式都可以来实现定位. 首先, 每一个任务都必须是一个 project 的有效属性, 使用任务名来作为属性名:

例子 15.4. 通过属性获取 tasks

build.gradle

task hello

println hello.name
println project.hello.name

Tasks 也可以通过 tasks collection 来得到.

例子 15.5. 通过 tasks collection 获取 tasks

build.gradle

task hello

println tasks.hello.name
println tasks['hello'].name

You can access tasks from any project using the task's path using the tasks.getByPath() method. You can call the getByPath() method with a task name, or a relative path, or an absolute path.

例子 15.6. 通过路径获取 tasks

build.gradle

project(':projectA') {
    task hello
}

task hello

println tasks.getByPath('hello').path
println tasks.getByPath(':hello').path
println tasks.getByPath('projectA:hello').path
println tasks.getByPath(':projectA:hello').path

gradle -q hello 的输出

> gradle -q hello
:hello
:hello
:projectA:hello
:projectA:hello

参考 TaskContainer 可以知道跟多关于定位 tasks 的选项.

Gradle 定义 tasks
Gradle 配置 tasks
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

Gradle 使用 Ant 插件

Gradle 使用 Ant 任务和 Ant 类型的构建

Gradle 导入一个 Ant 构建

Gradle Ant 的属性与引用

Gradle API

Gradle Gradle Plugins

Gradle 使用构建脚本块应用插件

Gradle 查找社区插件

Gradle 更多关于插件

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }