Skip to content

Instantly share code, notes, and snippets.

@qrtt1
Last active September 2, 2016 10:16
Show Gist options
  • Save qrtt1/55466f27a1672522ef6a16d71accb72a to your computer and use it in GitHub Desktop.
Save qrtt1/55466f27a1672522ef6a16d71accb72a to your computer and use it in GitHub Desktop.
Gradle Rule Base API
class ExtraTask extends RuleSource {
@Mutate void createCopyTasks(ModelMap<Task> tasks) {
tasks.grep({it.name.contains("package")})
.grep({!it.name.contains("Test")})
.each {
if(it.name.contains("package")) {
// it 就是 packageXXX 的 task,outputFile 就是他預計輸出的 apk
// 這欄位是查原始碼來的 http://bit.ly/2bH99aw
def outputFile = it.outputFile
// 接著我們建一個新的 copyXXX 的 task 讓原來的 packageXXX 相依它
def taskName = "copy" + (it.name - "package")
def copyTask = tasks.create(taskName, Copy) {
from outputFile
into outputFile.getParent()
rename {
it + "你眼睛業障重啊.apk"
}
}
it.dependsOn tasks[taskName]
}
}
}
}
apply plugin: ExtraTask
qty:MyApplication3 qrtt1$ ./gradlew model
To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/2.14.1/userguide/gradle_daemon.html.
Incremental java compilation is an incubating feature.
:model
------------------------------------------------------------
Root project
------------------------------------------------------------
+ tasks
| Type: org.gradle.model.ModelMap<org.gradle.api.Task>
| Creator: Project.<init>.tasks()
+ buildEnvironment
| Type: org.gradle.api.tasks.diagnostics.BuildEnvironmentReportTask
| Value: task ':buildEnvironment'
| Creator: tasks.addPlaceholderAction(buildEnvironment)
| Rules:
⤷ copyToTaskContainer
+ clean
| Type: org.gradle.api.tasks.Delete
| Value: task ':clean'
| Creator: Project.<init>.tasks.clean()
| Rules:
⤷ copyToTaskContainer
+ components
| Type: org.gradle.api.reporting.components.ComponentReport
| Value: task ':components'
| Creator: tasks.addPlaceholderAction(components)
| Rules:
⤷ copyToTaskContainer
+ dependencies
| Type: org.gradle.api.tasks.diagnostics.DependencyReportTask
| Value: task ':dependencies'
| Creator: tasks.addPlaceholderAction(dependencies)
| Rules:
⤷ copyToTaskContainer
+ dependencyInsight
| Type: org.gradle.api.tasks.diagnostics.DependencyInsightReportTask
| Value: task ':dependencyInsight'
| Creator: tasks.addPlaceholderAction(dependencyInsight)
| Rules:
⤷ HelpTasksPlugin.Rules#addDefaultDependenciesReportConfiguration(DependencyInsightReportTask, ServiceRegistry)
⤷ copyToTaskContainer
+ help
| Type: org.gradle.configuration.Help
| Value: task ':help'
| Creator: tasks.addPlaceholderAction(help)
| Rules:
⤷ copyToTaskContainer
+ init
| Type: org.gradle.buildinit.tasks.InitBuild
| Value: task ':init'
| Creator: tasks.addPlaceholderAction(init)
| Rules:
⤷ copyToTaskContainer
+ model
| Type: org.gradle.api.reporting.model.ModelReport
| Value: task ':model'
| Creator: tasks.addPlaceholderAction(model)
| Rules:
⤷ copyToTaskContainer
+ projects
| Type: org.gradle.api.tasks.diagnostics.ProjectReportTask
| Value: task ':projects'
| Creator: tasks.addPlaceholderAction(projects)
| Rules:
⤷ copyToTaskContainer
+ properties
| Type: org.gradle.api.tasks.diagnostics.PropertyReportTask
| Value: task ':properties'
| Creator: tasks.addPlaceholderAction(properties)
| Rules:
⤷ copyToTaskContainer
+ tasks
| Type: org.gradle.api.tasks.diagnostics.TaskReportTask
| Value: task ':tasks'
| Creator: tasks.addPlaceholderAction(tasks)
| Rules:
⤷ copyToTaskContainer
+ wrapper
| Type: org.gradle.api.tasks.wrapper.Wrapper
| Value: task ':wrapper'
| Creator: tasks.addPlaceholderAction(wrapper)
| Rules:
⤷ copyToTaskContainer
BUILD SUCCESSFUL
Total time: 13.04 secs
qty:MyApplication3 qrtt1$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment