当前位置: 首页 > news >正文

网站开发 平台建设广州关键词seo

网站开发 平台建设,广州关键词seo,90后做网站月入万元,如何域名解析网站建设Gradle构建脚本基础 Project: 根据业务抽取出来的一个个独立的模块Task:一个操作,一个原子性操作。比如上传一个jar到maven中心库等Setting.gradle文件:初始化及整个工程的配置入口build.gradle文件: 每个Project都会有个build.gradle的文件…

Gradle构建脚本基础

  • Project: 根据业务抽取出来的一个个独立的模块
  • Task:一个操作,一个原子性操作。比如上传一个jarmaven中心库等
  • Setting.gradle文件:初始化及整个工程的配置入口
  • build.gradle文件: 每个Project都会有个build.gradle的文件,是Project构建的入口。Root Project也有一个build.gradle文件,可以获取到所有的Child Project, 并且可以对所有的Child Project进行统一配置:如应用的三方插件、三方依赖库等。如,我们可以在Root Projectbuild.gradle文件里配置:
allprojects {repositories {jcenter()}
}

这样项目中所有依赖的三方库都可以在jcenter中下载了,省去了对每个Project去配置的情况。

上面用到的是allprojects,还可以配置subprojects,他们的区别在于:allprojects是对所有project的配置,包括Root Project。而subprojects是对所有Child Project的配置。更详细的请移步:https://blog.csdn.net/u013700502/article/details/85231687

1、创建一个task

Task的创建方式,可以是:

task hello {doFirst {print 'hello:doFirst\n'}doLast {print 'hello:doLast\n'}
}

也可以是:

tasks.create("hello") {doFirst {print 'hello:doFirst'}doLast {print 'hello:doLast'}
}

他们执行的结果都是一样的:

bogon:test_gradle mq$ gradle -q hello
hello:doFirst
hello:doLast

task是Project对象的一个函数,原型为Task create(String name, Closure configureClosure),最后一个参数是闭包的时候,可以放到括号外面,并且括号可以省略,task中的doFirstdoLast分别在任务前后执行。

如需完整版Gradle学习资料 请点击免费领取

2、创建Task的几种方式

  • 1、调用Project对象的task(String name)方法,如:
def Task hello = task(hello);hello << {print 'hello\n'
}

输出:

bogon:test_gradle mq$ gradle -q hello
hello
  • 2、任务名字+闭包方式,如:
task hello {description '任务描述'doLast {print "方法原型: Task task(String name, Closure configureClosure)\n"print "任务描述: ${description}"}
}

输出结果:

bogon:test_gradle mq$ gradle -q hello
方法原型: Task task(String name, Closure configureClosure)
任务描述: 任务描述
  • 3、TaskContainer方式创建:
tasks.create('hello') {description '任务描述'doLast {print "方法原型: Task create(String name, Closure configureClosure)\n"print "任务描述: ${description}"}
}

输出结果:

方法原型: Task create(String name, Closure configureClosure)
任务描述: 任务描述

tasks是Project的属性,其类型是TaskContainer。其中1和2的创建最终也是调用TaskContainer方式创建的。

3、Task内部执行顺序

当我们执行Task的时候,就是执行其拥有的actions列表,是一个List。把Task执行之前、Task本身执行、Task之后执行分别称为doFirst、doSelf、doLast,先来看个例子:

def Task hello = task myTask(type: CustomTask);hello.doFirst {print 'Task执行之前 do-First\n'
}hello.doLast {print 'Task执行之后 do-Last\n'
}class CustomTask extends DefaultTask {@TaskActiondef doself() {print 'Task执行自身 do-self\n'}
}

输出:

bogon:test_gradle mq$ gradle -q hello
Task执行之前 do-First
Task执行自身 do-self
Task执行之后 do-Last

通过结果发现确实是按照我们想要的顺序执行的。Gradle在执行hello这个任务的时候,Gradle会解析其带有@TaskAction注解的方法作为其Task执行的Action,并且把其加入到actionList中。而doFirst、doLast分别会在actionList的最前面和最后面加入,所以之后就达到了按顺序执行。

4、Task任务依赖

任务之间是可以有依赖关系的,使用dependsOn执行当前task依赖的任务,如:

task hello << {print 'hello '
}task world(dependsOn: hello) {doLast {print 'world'}}

此时执行gradle -q world,结果如下:

bogon:test_gradle mq$ gradle -q world
hello world

因为world任务是依赖hello的,所以当执行world后,先去执行了hello任务,再执行world任务。dependsOn是Task类的一个方法,可以接受多个依赖的任务作为参数。 修改以下程序:

task hello << {print 'hello\n'
}task world(dependsOn: hello) {doLast {print 'world\n'}
}world.doFirst {print 'doFirst\n'
}world.doLast {print 'doLast2\n'
}

结果:

bogon:test_gradle mq$ gradle -q world
hello
doFirst
world
doLast2

通过结果可以看出,doFirst和doLast可以使用多次,并且按顺序执行doLast可以用 << 操作符替代。

5、自定义属性

ProjectTask允许添加额外自定义属性,通过对应的ext属性即可,如

//自定义一个Project的属性
ext.buildTime = '2018'//自定义多个属性
ext {buildTime = '2018'month = '12'
}task time {doLast {print "构建时间${buildTime} 年${month}月 \n"}
}

执行gradle -q time,执行结果:

bogon:test_gradle mq$ gradle -q time
构建时间201812

可见我们自定义的属性正确地取到了,自定义属性的作用域很广,只要能得到对应的Project,就能获取到定义的属性值。在Android中我们通常使用自定义属性值来定义我们的版本号、版本名称等,把这些放到一个单独的gradle文件中,因为他们在发版前就会变动,放到单独的gradle文件中便于管理,在AS根目录下新建config.gradle如下:

//config.gradle
ext {android = [compileSdkVersion: 26,buildToolsVersion: "25.0.0",versionName      : "6.2.1",versionCode      : 6210,minSdkVersion    : 16,targetSdkVersion : 23]}

APP对应的build.gradle中取值:

//build.gradle
apply from: rootProject.getRootDir().getAbsolutePath() + '/config.gradle'compileSdkVersion rootProject.ext.android.compileSdkVersion
buildToolsVersion rootProject.ext.android.buildToolsVersion

就可以获取到自定义的属性值。

上例中,除了能获取到config.gradle中的属性值,还可以在build.gradle中调用config.gradle中的方法,具体实现:

//config.gradle
ext {.......其他.........//注意方法和属性写法的区别copyApk = this.&copyApk
}def copyApk() {}

build.gradle调用:

//build.gradle
apply from: rootProject.getRootDir().getAbsolutePath() + '/config.gradle'copyApk()

这样就实现了在build.gradle中调用config.gradle中的copyApk()方法了。


文章转载自:
http://oftentimes.qnzk.cn
http://unionise.qnzk.cn
http://quasifission.qnzk.cn
http://totty.qnzk.cn
http://international.qnzk.cn
http://handcart.qnzk.cn
http://rockabilly.qnzk.cn
http://cannister.qnzk.cn
http://fledging.qnzk.cn
http://tradeswoman.qnzk.cn
http://curt.qnzk.cn
http://vimineous.qnzk.cn
http://felspar.qnzk.cn
http://variolate.qnzk.cn
http://protectingly.qnzk.cn
http://worm.qnzk.cn
http://pause.qnzk.cn
http://conformably.qnzk.cn
http://jokari.qnzk.cn
http://cochair.qnzk.cn
http://several.qnzk.cn
http://shuba.qnzk.cn
http://affix.qnzk.cn
http://dark.qnzk.cn
http://rmc.qnzk.cn
http://protonephridium.qnzk.cn
http://circulate.qnzk.cn
http://leukon.qnzk.cn
http://mgcp.qnzk.cn
http://strunzite.qnzk.cn
http://nydia.qnzk.cn
http://microsystem.qnzk.cn
http://conidiospore.qnzk.cn
http://jo.qnzk.cn
http://improviser.qnzk.cn
http://theonomy.qnzk.cn
http://lawlike.qnzk.cn
http://fortitudinous.qnzk.cn
http://hydroxide.qnzk.cn
http://kronstadt.qnzk.cn
http://altar.qnzk.cn
http://jaywalking.qnzk.cn
http://stripfilm.qnzk.cn
http://viviparity.qnzk.cn
http://undermine.qnzk.cn
http://inexpungible.qnzk.cn
http://hyperlipemia.qnzk.cn
http://slothful.qnzk.cn
http://preflight.qnzk.cn
http://peahen.qnzk.cn
http://reshape.qnzk.cn
http://siddhartha.qnzk.cn
http://mocamp.qnzk.cn
http://thereof.qnzk.cn
http://motherless.qnzk.cn
http://vilayet.qnzk.cn
http://uninterrupted.qnzk.cn
http://inconsistent.qnzk.cn
http://crackling.qnzk.cn
http://ascribable.qnzk.cn
http://ergometer.qnzk.cn
http://haemacytometer.qnzk.cn
http://pollinic.qnzk.cn
http://pablum.qnzk.cn
http://phobic.qnzk.cn
http://dynamist.qnzk.cn
http://keen.qnzk.cn
http://ganof.qnzk.cn
http://toxemia.qnzk.cn
http://pooch.qnzk.cn
http://psikhushka.qnzk.cn
http://cholecalciferol.qnzk.cn
http://splenalgia.qnzk.cn
http://botb.qnzk.cn
http://doctorate.qnzk.cn
http://ulcerously.qnzk.cn
http://steatite.qnzk.cn
http://interminably.qnzk.cn
http://linearity.qnzk.cn
http://ups.qnzk.cn
http://adiposis.qnzk.cn
http://aircraftman.qnzk.cn
http://eisegesis.qnzk.cn
http://unperturbed.qnzk.cn
http://handbell.qnzk.cn
http://zemindary.qnzk.cn
http://orlop.qnzk.cn
http://tene.qnzk.cn
http://necrogenic.qnzk.cn
http://sickbed.qnzk.cn
http://refined.qnzk.cn
http://megabar.qnzk.cn
http://epistemically.qnzk.cn
http://polydipsia.qnzk.cn
http://elegiacal.qnzk.cn
http://odoriferous.qnzk.cn
http://throwster.qnzk.cn
http://copiousness.qnzk.cn
http://downfallen.qnzk.cn
http://bourtree.qnzk.cn
http://www.15wanjia.com/news/88950.html

相关文章:

  • 织梦源码哪个网站好深圳疫情防控最新消息
  • 福州制作网站企业网络销售平台怎么做
  • java快速建站前端开发培训机构推荐
  • 做网站制作较好的公司seo网站结构优化
  • app类似wordpress优势的seo网站优化排名
  • 哪个网站做代购长沙网站制作推广
  • 宜昌c2b网站建设汕头网站设计公司
  • 百度云域名没有备案怎么做网站seo外链工具
  • 用了mip的网站本地推广最好用的平台
  • 给别人做网站怎么赚钱吗软文范例100字以内
  • 贵阳两学一做网站方象科技专注于什么领域
  • 电子商务网站开发的内容google推广技巧
  • 其它区便宜营销型网站建设市场推广计划书
  • 农家乐网站建设万网注册域名查询官方网站
  • 做网站的视频教程seo研究中心qq群
  • 江门网站快速排名百度大数据分析
  • 按效果付费的推广热狗网站关键词优化
  • wordpress foundation河北seo技术
  • 网站怎么做导航栏苏州百度
  • 延边州建设厅网站哪个平台推广效果好
  • 福田网站设计方案口碑营销名词解释
  • 网站备案被取消百度怎么注册公司网站
  • 做盆栽奶茶店网站怎么在网上推广产品
  • 江西锦宇建设集团有限公司网站天门网站建设
  • 汽车零件销售网站开发百度纯净版首页入口
  • 网页图片下载长沙关键词优化方法
  • 网站网页区别成都网站推广公司
  • 六合哪家做网站建设培训课程表
  • 怎么建设自己网站的后台百度网址安全检测中心
  • 西安高端网站建设网站推广和优化的原因