task ex46OrderTask1 {
println 'ex46OrderTask1'
}
task ex46OrderTask2 {
println 'ex46OrderTask2'
}
ex46OrderTask1.mustRunAfter ex46OrderTask2
- 我们可以从中看出task的执行是有先后顺序的。
task ex47DisenabledTask {
println 'ex47DisenabledTask'
}
ex47DisenabledTask.enabled = false
- 这里使用了task的自有属性enabled,用于控制是否跳过这个程序来执行
task ex47DisenabledTask {
println 'ex47DisenabledTask'
}
ex47DisenabledTask.enabled=false
// 4.8
final String BUILD_APPS_ALL = "all";
final String BUILD_APPS_SHOUFA = "shoufa";
final String BUILD_APPS_EXCLUDE_SHOUFA = "exclude_shoufa";
task ex48QQRelease {
println "打应用宝的包"
}
task ex48BaiduRelease {
println "打百度的包"
}
task ex48HuaweiRelease {
println "打华为的包"
}
task ex48MiuiRelease {
println "打小米系统的包"
}
task build {
group BasePlugin.BUILD_GROUP
description "打渠道包"
}
build.dependsOn ex48QQRelease, ex48BaiduRelease, ex48HuaweiRelease, ex48MiuiRelease
ex48QQRelease.onlyIf {
def execute = false;
if (project.hasProperty("build_apps")) {
Object buildApps = project.property("build_apps")
if (BUILD_APPS_EXCLUDE_SHOUFA.equals(buildApps) || BUILD_APPS_ALL.equals(buildApps)) {
execute = true
} else {
execute = false
}
} else {
execute = true
}
execute
}
ex48BaiduRelease.onlyIf {
def execute = false;
if (project.hasProperty("build_apps")) {
Object buildApps = project.property("build_apps")
if (BUILD_APPS_EXCLUDE_SHOUFA.equals(buildApps) || BUILD_APPS_ALL.equals(buildApps)) {
execute = true
} else {
execute = false
}
} else {
execute = true
}
execute
}
ex48HuaweiRelease.onlyIf {
def execute = false;
if (project.hasProperty("build_apps")) {
Object buildApps = project.property("build_apps")
if (BUILD_APPS_EXCLUDE_SHOUFA.equals(buildApps) || BUILD_APPS_ALL.equals(buildApps)) {
execute = true
} else {
execute = false
}
} else {
execute = true
}
execute
}
ex48MiuiRelease.onlyIf {
def execute = false;
if (project.hasProperty("build_apps")) {
Object buildApps = project.property("build_apps")
if (BUILD_APPS_EXCLUDE_SHOUFA.equals(buildApps) || BUILD_APPS_ALL.equals(buildApps)) {
execute = true
} else {
execute = false
}
} else {
execute = true
}
execute
}
- 这里使用了-p表示为Project指定K-V格式的属性键值对,使用格式为-PK=V
- 第一个是全部构建,第二个是只打首发包,第三个是打除了首发包,虽然这么说,但是实际 *** 作,发现并不行
- 所有的任务都在TaskContainer之中运行,由其进行管理的,它是继承NamedDomainObjectCollection
public T findByName(String name) {
T value = findByNameWithoutRules(name);
if (value != null) {
return value;
}
applyRules(name);
return findByNameWithoutRules(name);
}
tasks.addRule("对该规则的一个描述,便于调试查看等") {
String taskName -> {
task(taskName) {
println "该${taskName}任务不存在,请查证后再执行"
}
}
}
task ex49RuleTask {
dependsOn missTask
}
- 自己添加规则,这里面介绍两个tasks的固有函数:
- Rule addRule(Rule rule);
- Rule addRule(String description, Closure ruleAction);
- 二进制插件就是实现了org.gradle.api.Plugin接口的插件,他们可以有plugin id
apply plugin:'java'
// 上面是一个短名,下面也有一个完整的名字
apply plugin:org.gradle.api.plugins.JavaPlugin
// 由于org.gradle.api.plugins是默认导入的,所以可以简写为
apply plugin:JavaPlugin
2.应用脚本插件
apply from:'version.gradle'
task ex52PrintlnTask {
println "App版本是:${versionName}, 版本号是:${versionCode}"
}
- 然后重新创建一个文件version.gradle
ext {
versionName = '1.0.0'
versionCode = 1
}
六、源码
- gitee路径:https://gitee.com/dongqianrui/AndroidStudioProject/tree/master/Test1
- CSDN:https://blog.csdn.net/weixin_44630050
- 博客园:https://www.cnblogs.com/ruigege0000/
- 欢迎关注微信公众号:傅里叶变换,个人账号,仅用于技术交流
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)