Skip to content

Commit 0563972

Browse files
committed
Switch registering tasks to lazy
1 parent b866e57 commit 0563972

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetectorPlugin.kt

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,15 @@ class AffectedModuleDetectorPlugin : Plugin<Project> {
9393
customTasks: Set<AffectedModuleTaskType>
9494
) {
9595
customTasks.forEach { taskType ->
96-
val task = rootProject.tasks.register(taskType.commandByImpact).get()
97-
task.group = CUSTOM_TASK_GROUP_NAME
98-
task.description = taskType.taskDescription
99-
disableConfigCache(task)
100-
101-
rootProject.subprojects { project ->
102-
pluginIds.forEach { pluginId ->
103-
withPlugin(pluginId, task, taskType, project)
96+
rootProject.tasks.register(taskType.commandByImpact) { task ->
97+
task.group = CUSTOM_TASK_GROUP_NAME
98+
task.description = taskType.taskDescription
99+
disableConfigCache(task)
100+
101+
rootProject.subprojects { project ->
102+
pluginIds.forEach { pluginId ->
103+
withPlugin(pluginId, task, taskType, project)
104+
}
104105
}
105106
}
106107
}
@@ -134,20 +135,19 @@ class AffectedModuleDetectorPlugin : Plugin<Project> {
134135
taskType: AffectedModuleTaskType,
135136
groupName: String
136137
) {
137-
val task = rootProject.tasks.register(taskType.commandByImpact).get()
138-
task.group = groupName
139-
task.description = taskType.taskDescription
140-
disableConfigCache(task)
138+
rootProject.tasks.register(taskType.commandByImpact) { task ->
139+
task.group = groupName
140+
task.description = taskType.taskDescription
141+
disableConfigCache(task)
141142

142-
rootProject.subprojects { project ->
143-
project.afterEvaluate { evaluatedProject ->
143+
rootProject.subprojects { project ->
144144
pluginIds.forEach { pluginId ->
145145
if (pluginId == PLUGIN_JAVA_LIBRARY || pluginId == PLUGIN_KOTLIN) {
146146
if (taskType == InternalTaskType.ANDROID_JVM_TEST) {
147-
withPlugin(pluginId, task, InternalTaskType.JVM_TEST, evaluatedProject)
147+
withPlugin(pluginId, task, InternalTaskType.JVM_TEST, project)
148148
}
149149
} else {
150-
withPlugin(pluginId, task, taskType, evaluatedProject)
150+
withPlugin(pluginId, task, taskType, project)
151151
}
152152
}
153153
}
@@ -172,12 +172,10 @@ class AffectedModuleDetectorPlugin : Plugin<Project> {
172172
task.dependsOn(path)
173173
}
174174

175-
project.afterEvaluate {
176-
project.tasks.findByPath(path)?.onlyIf { task ->
177-
when {
178-
!AffectedModuleDetector.isProjectEnabled(task.project) -> true
179-
else -> AffectedModuleDetector.isProjectAffected(task.project)
180-
}
175+
project.tasks.findByPath(path)?.onlyIf { task ->
176+
when {
177+
!AffectedModuleDetector.isProjectEnabled(task.project) -> true
178+
else -> AffectedModuleDetector.isProjectAffected(task.project)
181179
}
182180
}
183181
}

affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetectorPluginTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class AffectedModuleDetectorPluginTest {
8282
// GIVEN
8383
val task = fakeTask
8484
val plugin = AffectedModuleDetectorPlugin()
85+
rootProject.pluginManager.apply(AffectedModuleDetectorPlugin::class.java)
8586

8687
// WHEN
8788
plugin.registerInternalTask(

0 commit comments

Comments
 (0)