Gradle task释义

getTasksByName释义
getTasksByName
Set<Task> getTasksByName​(String name,
                         boolean recursive)
Returns the set of tasks with the given name contained in this project, and optionally its subprojects. NOTE: This is an expensive operation since it requires all projects to be configured.

Parameters:
name - The name of the task to locate.
recursive - If true, returns the tasks of this project and its subprojects. If false, returns the tasks of just this project.
Returns:
The set of tasks. Returns an empty set if no such tasks exist in this project.
AbstractCopyTask使用
task initConfig(type: Copy) {
     from('src/main/config') {
         include '**/*.properties'
         include '**/*.xml'
         filter(ReplaceTokens, tokens: [version: '2.3.1'])
     }
     from('src/main/config') {
         exclude '**/*.properties', '**/*.xml'
     }
     from('src/main/languages') {
         rename 'EN_US_(.*)', '$1'
     }
     into 'build/target/config'
     exclude '**/*.bak'

     includeEmptyDirs = false

     with dataContent
 }

工程使用

工程中Task使用
task copyAuK(type: Copy) {
    from("${rootProject.projectDir.path}/au/build/outputs/aar/")
    into("${rootProject.projectDir.path}/app/libs/")
    include('xx.aar')
//    rename('', '')
}

task packageSdk() {
    dependsOn(
            rootProject.project(':xx').getTasksByName('assembleRelease', false),
            rootProject.project(':xx').getTasksByName('assembleRelease', false),
            rootProject.project(':xx').getTasksByName('assembleRelease', false),
            rootProject.project(':xx').getTasksByName('assembleRelease', false)
    )
    finalizedBy = ["xx", "xx", "xx", "copyAu"]
    doLast { println "完成打包 " }
	mustRunAfter('xx 在部分失败的情况下做一些必须做的同步上传')
}