@@ -77,10 +77,7 @@ class AffectedModuleDetectorPlugin : Plugin<Project> {
7777 }
7878
7979 private fun registerCustomTasks (rootProject : Project ) {
80- val mainConfiguration = requireNotNull(
81- value = rootProject.extensions.findByName(AffectedModuleConfiguration .name),
82- lazyMessage = { " Unable to find ${AffectedTestConfiguration .name} in $rootProject " }
83- ) as AffectedModuleConfiguration
80+ val mainConfiguration = requireConfiguration(rootProject)
8481
8582 rootProject.afterEvaluate {
8683 registerCustomTasks(rootProject, mainConfiguration.customTasks)
@@ -93,14 +90,15 @@ class AffectedModuleDetectorPlugin : Plugin<Project> {
9390 customTasks : Set <AffectedModuleTaskType >
9491 ) {
9592 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)
93+ rootProject.tasks.register(taskType.commandByImpact) { task ->
94+ task.group = CUSTOM_TASK_GROUP_NAME
95+ task.description = taskType.taskDescription
96+ disableConfigCache(task)
97+
98+ rootProject.subprojects { project ->
99+ pluginIds.forEach { pluginId ->
100+ withPlugin(pluginId, task, taskType, project)
101+ }
104102 }
105103 }
106104 }
@@ -134,20 +132,19 @@ class AffectedModuleDetectorPlugin : Plugin<Project> {
134132 taskType : AffectedModuleTaskType ,
135133 groupName : String
136134 ) {
137- val task = rootProject.tasks.register(taskType.commandByImpact).get()
138- task.group = groupName
139- task.description = taskType.taskDescription
140- disableConfigCache(task)
135+ rootProject.tasks.register(taskType.commandByImpact) { task ->
136+ task.group = groupName
137+ task.description = taskType.taskDescription
138+ disableConfigCache(task)
141139
142- rootProject.subprojects { project ->
143- project.afterEvaluate { evaluatedProject ->
140+ rootProject.subprojects { project ->
144141 pluginIds.forEach { pluginId ->
145142 if (pluginId == PLUGIN_JAVA_LIBRARY || pluginId == PLUGIN_KOTLIN ) {
146143 if (taskType == InternalTaskType .ANDROID_JVM_TEST ) {
147- withPlugin(pluginId, task, InternalTaskType .JVM_TEST , evaluatedProject )
144+ withPlugin(pluginId, task, InternalTaskType .JVM_TEST , project )
148145 }
149146 } else {
150- withPlugin(pluginId, task, taskType, evaluatedProject )
147+ withPlugin(pluginId, task, taskType, project )
151148 }
152149 }
153150 }
@@ -166,18 +163,22 @@ class AffectedModuleDetectorPlugin : Plugin<Project> {
166163 testType : AffectedModuleTaskType ,
167164 project : Project
168165 ) {
166+ val config = requireConfiguration(project)
167+
168+ fun isExcludedModule (configuration : AffectedModuleConfiguration , path : String ): Boolean {
169+ return configuration.excludedModules.find { path.startsWith(" :$it " ) } != null
170+ }
171+
169172 project.pluginManager.withPlugin(pluginId) {
170173 getAffectedPath(testType, project)?.let { path ->
171- if (AffectedModuleDetector .isProjectProvided(project)) {
174+ if (AffectedModuleDetector .isProjectProvided(project) && ! isExcludedModule(config, path) ) {
172175 task.dependsOn(path)
173176 }
174177
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- }
178+ project.tasks.findByPath(path)?.onlyIf { task ->
179+ when {
180+ ! AffectedModuleDetector .isProjectEnabled(task.project) -> true
181+ else -> AffectedModuleDetector .isProjectAffected(task.project)
181182 }
182183 }
183184 }
@@ -249,6 +250,13 @@ class AffectedModuleDetectorPlugin : Plugin<Project> {
249250 }
250251 }
251252
253+ private fun requireConfiguration (project : Project ): AffectedModuleConfiguration {
254+ return requireNotNull(
255+ value = project.rootProject.extensions.findByName(AffectedModuleConfiguration .name),
256+ lazyMessage = { " Unable to find ${AffectedModuleConfiguration .name} in ${project.rootProject} " }
257+ ) as AffectedModuleConfiguration
258+ }
259+
252260 companion object {
253261
254262 @VisibleForTesting
0 commit comments