Skip to content

Commit cb69686

Browse files
committed
Use onlyIf instead of isEnabled when resolving srcDirs to determine
whether tasks should be executed. This fixes a bug where tasks would not be executed, because srcDirs would not yet exist at configuration time.
1 parent 2defc0b commit cb69686

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version=0.4.0-SNAPSHOT
1+
version=0.4.0.mysugr.2
22
group=org.jetbrains.kotlinx
33

44
kotlinVersion=1.4.30

src/main/kotlin/BinaryCompatibilityValidatorPlugin.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ private fun Project.configureKotlinCompilation(
8383
val projectName = project.name
8484
val apiBuildDir = file(buildDir.resolve(API_DIR))
8585
val apiBuild = task<KotlinApiBuildTask>("apiBuild", extension) {
86-
// Do not enable task for empty umbrella modules
87-
isEnabled = apiCheckEnabled(extension) && compilation.allKotlinSourceSets.any { it.kotlin.srcDirs.any { it.exists() } }
86+
// Do not execute task for empty umbrella modules
87+
onlyIf { compilation.allKotlinSourceSets.any { it.kotlin.srcDirs.any { it.exists() } } }
88+
isEnabled = apiCheckEnabled(extension)
8889
// 'group' is not specified deliberately so it will be hidden from ./gradlew tasks
8990
description =
9091
"Builds Kotlin API for 'main' compilations of $projectName. Complementary task and shouldn't be called manually"
@@ -131,7 +132,9 @@ private fun Project.configureCheckTasks(
131132
val projectName = project.name
132133
val apiCheckDir = file(projectDir.resolve(API_DIR))
133134
val apiCheck = task<ApiCompareCompareTask>("apiCheck") {
134-
isEnabled = apiCheckEnabled(extension) && apiBuild.map { it.enabled }.getOrElse(true)
135+
// Do not execute task for empty umbrella modules
136+
onlyIf { apiBuild.get().isOnlyIf() }
137+
isEnabled = apiCheckEnabled(extension)
135138
group = "verification"
136139
description = "Checks signatures of public API against the golden value in API folder for $projectName"
137140
projectApiDir = if (apiCheckDir.exists()) {
@@ -145,7 +148,9 @@ private fun Project.configureCheckTasks(
145148
}
146149

147150
task<Sync>("apiDump") {
148-
isEnabled = apiCheckEnabled(extension) && apiBuild.map { it.enabled }.getOrElse(true)
151+
// Do not execute task for empty umbrella modules
152+
onlyIf { apiBuild.get().isOnlyIf() }
153+
isEnabled = apiCheckEnabled(extension)
149154
group = "other"
150155
description = "Syncs API from build dir to $API_DIR dir for $projectName"
151156
from(apiBuildDir)
@@ -158,6 +163,8 @@ private fun Project.configureCheckTasks(
158163
project.tasks.getByName("check").dependsOn(apiCheck)
159164
}
160165

166+
private fun KotlinApiBuildTask.isOnlyIf(): Boolean = onlyIf.isSatisfiedBy(this)
167+
161168
inline fun <reified T : Task> Project.task(
162169
name: String,
163170
noinline configuration: T.() -> Unit

0 commit comments

Comments
 (0)