-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdisable-metadata-subtasks.gradle
51 lines (41 loc) · 1.86 KB
/
disable-metadata-subtasks.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// On circleci we build and test each artifact in separate job.
// So when pipeline comes to publishing all artifacts have been built already.
//
// Gradle tasks generateMetadataFileForXXX depend on bundleReleaseAar task for each module,
// which forces gradle to rebuild artifacts from scratch.
//
// This plugin disables all children of generateMetadataFileForXXX tasks. So we publish tested artifacts,
// instead of building new ones from the same sources.
//
// When plugin is successfully applied you can see in the gradle output skipped tasks, like:
// > Task :sync-android-kt:bundleReleaseAar SKIPPED
// > Task :generateMetadataFileForNativeSyncReleasePublication
gradle.taskGraph.whenReady {
println("Disabling child tasks of generateMetadataFileForXXX...")
// Getting a private field is possible thanks to groovy not honoring the private modifier
def executionPlan = gradle.taskGraph.executionPlan.contents
def tasksOfCurrentProject = executionPlan.entryNodes.findAll { node ->
node.hasProperty('task') && node.task.project == project
}
tasksOfCurrentProject.each { taskNode ->
def generateMetadataNodes = findAllRecursive(taskNode) { it.task.name.startsWith("generateMetadataFileFor") }
generateMetadataNodes.each { disableChildrenRecursive(it) }
}
}
def findAllRecursive(taskNode, predicate, result = new HashSet<Node>()) {
if (predicate(taskNode)) {
result.add(taskNode)
}
Set<Node> children = taskNode.dependencySuccessors.findAll { it.hasProperty('task') }
children.each { child ->
findAllRecursive(child, predicate, result)
}
return result
}
def disableChildrenRecursive(taskNode) {
Set<Node> children = taskNode.dependencySuccessors.findAll { it.hasProperty('task') }
children.each { child ->
child.task.setEnabled(false)
disableChildrenRecursive(child)
}
}