Fix adding associated compilation for Kotlin Native.
Kotlin native does not support 'compileOnly' or 'runtimeOnly' configurations. In this case associated compilations are added as 'implementation'. ^KT-45911 Fixed
This commit is contained in:
+74
-21
@@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.jetbrains.kotlin.gradle
|
package org.jetbrains.kotlin.gradle
|
||||||
|
|
||||||
|
import org.gradle.api.logging.LogLevel
|
||||||
import org.jetbrains.kotlin.gradle.native.GeneralNativeIT.Companion.checkNativeCommandLineArguments
|
import org.jetbrains.kotlin.gradle.native.GeneralNativeIT.Companion.checkNativeCommandLineArguments
|
||||||
import org.jetbrains.kotlin.gradle.native.GeneralNativeIT.Companion.containsSequentially
|
import org.jetbrains.kotlin.gradle.native.GeneralNativeIT.Companion.containsSequentially
|
||||||
import org.gradle.api.logging.configuration.WarningMode
|
import org.gradle.api.logging.configuration.WarningMode
|
||||||
@@ -693,8 +694,9 @@ class NewMultiplatformIT : BaseGradleIT() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testLanguageSettingsClosureForKotlinDsl() = with(transformNativeTestProjectWithPluginDsl("sample-lib-gradle-kotlin-dsl", gradleVersion, "new-mpp-lib-and-app")) {
|
fun testLanguageSettingsClosureForKotlinDsl() =
|
||||||
gradleBuildScript().appendText(
|
with(transformNativeTestProjectWithPluginDsl("sample-lib-gradle-kotlin-dsl", gradleVersion, "new-mpp-lib-and-app")) {
|
||||||
|
gradleBuildScript().appendText(
|
||||||
"\n" + """
|
"\n" + """
|
||||||
kotlin.sourceSets.all {
|
kotlin.sourceSets.all {
|
||||||
languageSettings {
|
languageSettings {
|
||||||
@@ -703,16 +705,16 @@ class NewMultiplatformIT : BaseGradleIT() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
|
|
||||||
listOf("compileKotlinMetadata", "compileKotlinJvm6", "compileKotlinNodeJs").forEach {
|
listOf("compileKotlinMetadata", "compileKotlinJvm6", "compileKotlinNodeJs").forEach {
|
||||||
build(it) {
|
build(it) {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
assertTasksExecuted(":$it")
|
assertTasksExecuted(":$it")
|
||||||
assertContains("-language-version 1.3", "-api-version 1.3")
|
assertContains("-language-version 1.3", "-api-version 1.3")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testLanguageSettingsApplied() = with(transformNativeTestProject("sample-lib", gradleVersion, "new-mpp-lib-and-app")) {
|
fun testLanguageSettingsApplied() = with(transformNativeTestProject("sample-lib", gradleVersion, "new-mpp-lib-and-app")) {
|
||||||
@@ -1409,19 +1411,19 @@ class NewMultiplatformIT : BaseGradleIT() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
assertContains(">> :app:testNonTransitiveDependencyNotationApiDependenciesMetadata --> kotlin-reflect-${defaultBuildOptions().kotlinVersion}.jar")
|
assertContains(">> :app:testNonTransitiveDependencyNotationApiDependenciesMetadata --> kotlin-reflect-${defaultBuildOptions().kotlinVersion}.jar")
|
||||||
assertEquals(
|
assertEquals(
|
||||||
1,
|
1,
|
||||||
(Regex.escape(">> :app:testNonTransitiveStringNotationApiDependenciesMetadata") + " .*").toRegex().findAll(output)
|
(Regex.escape(">> :app:testNonTransitiveStringNotationApiDependenciesMetadata") + " .*").toRegex().findAll(output)
|
||||||
.count()
|
.count()
|
||||||
)
|
)
|
||||||
|
|
||||||
assertContains(">> :app:testExplicitKotlinVersionApiDependenciesMetadata --> kotlin-reflect-1.3.0.jar")
|
assertContains(">> :app:testExplicitKotlinVersionApiDependenciesMetadata --> kotlin-reflect-1.3.0.jar")
|
||||||
assertContains(">> :app:testExplicitKotlinVersionImplementationDependenciesMetadata --> kotlin-reflect-1.2.71.jar")
|
assertContains(">> :app:testExplicitKotlinVersionImplementationDependenciesMetadata --> kotlin-reflect-1.2.71.jar")
|
||||||
assertContains(">> :app:testExplicitKotlinVersionCompileOnlyDependenciesMetadata --> kotlin-reflect-1.2.70.jar")
|
assertContains(">> :app:testExplicitKotlinVersionCompileOnlyDependenciesMetadata --> kotlin-reflect-1.2.70.jar")
|
||||||
assertContains(">> :app:testExplicitKotlinVersionRuntimeOnlyDependenciesMetadata --> kotlin-reflect-1.2.60.jar")
|
assertContains(">> :app:testExplicitKotlinVersionRuntimeOnlyDependenciesMetadata --> kotlin-reflect-1.2.60.jar")
|
||||||
|
|
||||||
assertContains(">> :app:testProjectWithConfigurationApiDependenciesMetadata --> output.txt")
|
assertContains(">> :app:testProjectWithConfigurationApiDependenciesMetadata --> output.txt")
|
||||||
}
|
}
|
||||||
|
|
||||||
testDependencies()
|
testDependencies()
|
||||||
|
|
||||||
@@ -1712,4 +1714,55 @@ class NewMultiplatformIT : BaseGradleIT() {
|
|||||||
assertEquals("org.sample.one:foo", jsManifest[KLIB_PROPERTY_UNIQUE_NAME])
|
assertEquals("org.sample.one:foo", jsManifest[KLIB_PROPERTY_UNIQUE_NAME])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Test
|
||||||
|
fun testNativeCompilationShouldNotProduceAnyWarningsForAssociatedCompilations() {
|
||||||
|
with(Project("native-common-dependencies-warning", minLogLevel = LogLevel.INFO)) {
|
||||||
|
setupWorkingDir()
|
||||||
|
build("help") {
|
||||||
|
assertSuccessful()
|
||||||
|
assertNotContains("A compileOnly dependency is used in the Kotlin/Native target '${detectNativeEnabledCompilation()}':")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testNativeCompilationShouldProduceWarningOnCompileOnlyCommonDependency() {
|
||||||
|
with(Project("native-common-dependencies-warning", minLogLevel = LogLevel.INFO)) {
|
||||||
|
setupWorkingDir()
|
||||||
|
gradleBuildScript().modify {
|
||||||
|
it.replaceFirst("//compileOnly:", "")
|
||||||
|
}
|
||||||
|
build("help") {
|
||||||
|
assertSuccessful()
|
||||||
|
assertContains("A compileOnly dependency is used in the Kotlin/Native target '${detectNativeEnabledCompilation()}':")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testNativeCompilationCompileOnlyDependencyWarningCouldBeDisabled() {
|
||||||
|
with(Project("native-common-dependencies-warning", minLogLevel = LogLevel.INFO)) {
|
||||||
|
setupWorkingDir()
|
||||||
|
gradleBuildScript().modify {
|
||||||
|
it.replaceFirst("//compileOnly:", "")
|
||||||
|
}
|
||||||
|
projectDir.resolve("gradle.properties").writeText(
|
||||||
|
"""
|
||||||
|
kotlin.native.ignoreIncorrectDependencies = true
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
build("help") {
|
||||||
|
assertSuccessful()
|
||||||
|
assertNotContains("A compileOnly dependency is used in the Kotlin/Native target '${detectNativeEnabledCompilation()}':")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun detectNativeEnabledCompilation(): String = when {
|
||||||
|
HostManager.hostIsLinux -> "linuxX64"
|
||||||
|
HostManager.hostIsMingw -> "mingwX64"
|
||||||
|
HostManager.hostIsMac -> "macosX64"
|
||||||
|
else -> throw AssertionError("Host ${HostManager.host} is not supported for this test")
|
||||||
|
}
|
||||||
|
}
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
plugins {
|
||||||
|
kotlin("multiplatform")
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
linuxX64()
|
||||||
|
mingwX64()
|
||||||
|
macosX64()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
//compileOnly: commonMainCompileOnly("org.jetbrains.kotlin:kotlin-stdlib")
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
pluginManagement {
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
gradlePluginPortal()
|
||||||
|
}
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id("org.jetbrains.kotlin.multiplatform") version "${extra["kotlin_version"]}"
|
||||||
|
}
|
||||||
|
}
|
||||||
-1
@@ -254,7 +254,6 @@ abstract class AbstractKotlinCompilation<T : KotlinCommonOptions>(
|
|||||||
|
|
||||||
protected open fun addAssociateCompilationDependencies(other: KotlinCompilation<*>) {
|
protected open fun addAssociateCompilationDependencies(other: KotlinCompilation<*>) {
|
||||||
with(target.project) {
|
with(target.project) {
|
||||||
|
|
||||||
dependencies.add(
|
dependencies.add(
|
||||||
compileOnlyConfigurationName,
|
compileOnlyConfigurationName,
|
||||||
project.files(Callable { other.output.classesDirs })
|
project.files(Callable { other.output.classesDirs })
|
||||||
|
|||||||
+14
@@ -104,6 +104,20 @@ class KotlinNativeCompilation(
|
|||||||
|
|
||||||
val binariesTaskName: String
|
val binariesTaskName: String
|
||||||
get() = lowerCamelCaseName(target.disambiguationClassifier, compilationName, "binaries")
|
get() = lowerCamelCaseName(target.disambiguationClassifier, compilationName, "binaries")
|
||||||
|
|
||||||
|
override fun addAssociateCompilationDependencies(other: KotlinCompilation<*>) {
|
||||||
|
with(target.project) {
|
||||||
|
// Kotlin native does not support either 'compileOnly' or 'runtimeOnly' configurations
|
||||||
|
dependencies.add(
|
||||||
|
implementationConfigurationName,
|
||||||
|
project.files({ other.output.classesDirs })
|
||||||
|
)
|
||||||
|
|
||||||
|
configurations.named(implementationConfigurationName).configure {
|
||||||
|
it.extendsFrom(configurations.findByName(other.implementationConfigurationName))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class KotlinSharedNativeCompilation(override val target: KotlinMetadataTarget, val konanTargets: List<KonanTarget>, name: String) :
|
class KotlinSharedNativeCompilation(override val target: KotlinMetadataTarget, val konanTargets: List<KonanTarget>, name: String) :
|
||||||
|
|||||||
Reference in New Issue
Block a user