Fix KNPE due to publications processing order in Gradle 4.7

A KNPE happened because Gradle 4.7 (but not 4.8+) requested a
publication's dependencies before all other publications were created.

Issue #KT-27231 Fixed
This commit is contained in:
Sergey Igushkin
2018-09-27 00:39:04 +03:00
parent 334c776b92
commit 58a8411575
2 changed files with 6 additions and 3 deletions
@@ -21,7 +21,7 @@ import kotlin.test.assertFalse
import kotlin.test.assertTrue
class NewMultiplatformIT : BaseGradleIT() {
val gradleVersion = GradleVersionRequired.AtLeast("4.8")
val gradleVersion = GradleVersionRequired.AtLeast("4.7")
val nativeHostTargetName = when {
HostManager.hostIsMingw -> "mingw64"
@@ -132,8 +132,7 @@ class KotlinMultiplatformPlugin(
publishTask.onlyIf { publishTask.publication != rootPublication || project.multiplatformExtension!!.isGradleMetadataAvailable }
}
// Create separate publications for all publishable targets
targets.matching { it.publishable }.all { target ->
fun createTargetPublication(target: KotlinTarget) {
val variant = target.component as KotlinVariant
val name = target.name
@@ -156,6 +155,10 @@ class KotlinMultiplatformPlugin(
it.execute(variantPublication)
}
}
// Enforce the order of creating the publications, since the metadata publication is used in the other publications:
createTargetPublication(targets.getByName(METADATA_TARGET_NAME))
targets.matching { it.publishable && it.name != METADATA_TARGET_NAME }.all(::createTargetPublication)
}
project.components.add(kotlinSoftwareComponent)