[Gradle] Partially restore top-level compiler options DSL in MPP
To support configuring free compiler arguments for all shared source
sets (KT-61573), we restore 'compilerOptions { }' DSL in the
multiplatform extension.
To avoid user confusion on accidentally using 'compilerOptions {}'
inside Kotlin targets and Kotlin compilations DSL, similar methods with
ERROR deprecation level were added into `KotlinTarget` and
`KotlinCompilation` interfaces. Invoking these interfaces will throw
UnsupportedOperationException. Such an approach works both for Kotlin
and Groove Gradle scripts.
^KT-63491 Fixed
This commit is contained in:
committed by
Space Team
parent
f32fd314f8
commit
ffa6bfc95e
@@ -705,6 +705,8 @@ public abstract interface class org/jetbrains/kotlin/gradle/plugin/KotlinCompila
|
||||
public abstract fun associateWith (Lorg/jetbrains/kotlin/gradle/plugin/KotlinCompilation;)V
|
||||
public abstract fun attributes (Lkotlin/jvm/functions/Function1;)V
|
||||
public abstract fun attributes (Lorg/gradle/api/Action;)V
|
||||
public abstract fun compilerOptions (Lkotlin/jvm/functions/Function1;)V
|
||||
public abstract fun compilerOptions (Lorg/gradle/api/Action;)V
|
||||
public abstract fun defaultSourceSet (Lkotlin/jvm/functions/Function1;)V
|
||||
public abstract fun defaultSourceSet (Lorg/gradle/api/Action;)V
|
||||
public abstract fun getAllAssociatedCompilations ()Ljava/util/Set;
|
||||
@@ -745,6 +747,8 @@ public final class org/jetbrains/kotlin/gradle/plugin/KotlinCompilation$Companio
|
||||
public final class org/jetbrains/kotlin/gradle/plugin/KotlinCompilation$DefaultImpls {
|
||||
public static fun attributes (Lorg/jetbrains/kotlin/gradle/plugin/KotlinCompilation;Lkotlin/jvm/functions/Function1;)V
|
||||
public static fun attributes (Lorg/jetbrains/kotlin/gradle/plugin/KotlinCompilation;Lorg/gradle/api/Action;)V
|
||||
public static fun compilerOptions (Lorg/jetbrains/kotlin/gradle/plugin/KotlinCompilation;Lkotlin/jvm/functions/Function1;)V
|
||||
public static fun compilerOptions (Lorg/jetbrains/kotlin/gradle/plugin/KotlinCompilation;Lorg/gradle/api/Action;)V
|
||||
public static fun defaultSourceSet (Lorg/jetbrains/kotlin/gradle/plugin/KotlinCompilation;Lorg/gradle/api/Action;)V
|
||||
public static fun getAssociateWith (Lorg/jetbrains/kotlin/gradle/plugin/KotlinCompilation;)Ljava/util/List;
|
||||
public static fun getDefaultSourceSetName (Lorg/jetbrains/kotlin/gradle/plugin/KotlinCompilation;)Ljava/lang/String;
|
||||
@@ -776,6 +780,8 @@ public abstract interface class org/jetbrains/kotlin/gradle/plugin/KotlinCompila
|
||||
public final class org/jetbrains/kotlin/gradle/plugin/KotlinCompilationToRunnableFiles$DefaultImpls {
|
||||
public static fun attributes (Lorg/jetbrains/kotlin/gradle/plugin/KotlinCompilationToRunnableFiles;Lkotlin/jvm/functions/Function1;)V
|
||||
public static fun attributes (Lorg/jetbrains/kotlin/gradle/plugin/KotlinCompilationToRunnableFiles;Lorg/gradle/api/Action;)V
|
||||
public static fun compilerOptions (Lorg/jetbrains/kotlin/gradle/plugin/KotlinCompilationToRunnableFiles;Lkotlin/jvm/functions/Function1;)V
|
||||
public static fun compilerOptions (Lorg/jetbrains/kotlin/gradle/plugin/KotlinCompilationToRunnableFiles;Lorg/gradle/api/Action;)V
|
||||
public static fun defaultSourceSet (Lorg/jetbrains/kotlin/gradle/plugin/KotlinCompilationToRunnableFiles;Lorg/gradle/api/Action;)V
|
||||
public static fun getAssociateWith (Lorg/jetbrains/kotlin/gradle/plugin/KotlinCompilationToRunnableFiles;)Ljava/util/List;
|
||||
public static fun getDefaultSourceSetName (Lorg/jetbrains/kotlin/gradle/plugin/KotlinCompilationToRunnableFiles;)Ljava/lang/String;
|
||||
@@ -793,6 +799,8 @@ public abstract interface class org/jetbrains/kotlin/gradle/plugin/KotlinCompila
|
||||
public final class org/jetbrains/kotlin/gradle/plugin/KotlinCompilationWithResources$DefaultImpls {
|
||||
public static fun attributes (Lorg/jetbrains/kotlin/gradle/plugin/KotlinCompilationWithResources;Lkotlin/jvm/functions/Function1;)V
|
||||
public static fun attributes (Lorg/jetbrains/kotlin/gradle/plugin/KotlinCompilationWithResources;Lorg/gradle/api/Action;)V
|
||||
public static fun compilerOptions (Lorg/jetbrains/kotlin/gradle/plugin/KotlinCompilationWithResources;Lkotlin/jvm/functions/Function1;)V
|
||||
public static fun compilerOptions (Lorg/jetbrains/kotlin/gradle/plugin/KotlinCompilationWithResources;Lorg/gradle/api/Action;)V
|
||||
public static fun defaultSourceSet (Lorg/jetbrains/kotlin/gradle/plugin/KotlinCompilationWithResources;Lorg/gradle/api/Action;)V
|
||||
public static fun getAssociateWith (Lorg/jetbrains/kotlin/gradle/plugin/KotlinCompilationWithResources;)Ljava/util/List;
|
||||
public static fun getDefaultSourceSetName (Lorg/jetbrains/kotlin/gradle/plugin/KotlinCompilationWithResources;)Ljava/lang/String;
|
||||
@@ -1121,6 +1129,8 @@ public final class org/jetbrains/kotlin/gradle/plugin/KotlinSourceSetTree$Compan
|
||||
public abstract interface class org/jetbrains/kotlin/gradle/plugin/KotlinTarget : org/gradle/api/Named, org/gradle/api/attributes/HasAttributes, org/jetbrains/kotlin/gradle/plugin/HasProject, org/jetbrains/kotlin/tooling/core/HasMutableExtras {
|
||||
public abstract fun attributes (Lkotlin/jvm/functions/Function1;)V
|
||||
public abstract fun attributes (Lorg/gradle/api/Action;)V
|
||||
public abstract fun compilerOptions (Lkotlin/jvm/functions/Function1;)V
|
||||
public abstract fun compilerOptions (Lorg/gradle/api/Action;)V
|
||||
public abstract fun getApiElementsConfigurationName ()Ljava/lang/String;
|
||||
public abstract fun getArtifactsTaskName ()Ljava/lang/String;
|
||||
public abstract fun getCompilations ()Lorg/gradle/api/NamedDomainObjectContainer;
|
||||
@@ -1143,6 +1153,8 @@ public abstract interface class org/jetbrains/kotlin/gradle/plugin/KotlinTarget
|
||||
public final class org/jetbrains/kotlin/gradle/plugin/KotlinTarget$DefaultImpls {
|
||||
public static fun attributes (Lorg/jetbrains/kotlin/gradle/plugin/KotlinTarget;Lkotlin/jvm/functions/Function1;)V
|
||||
public static fun attributes (Lorg/jetbrains/kotlin/gradle/plugin/KotlinTarget;Lorg/gradle/api/Action;)V
|
||||
public static fun compilerOptions (Lorg/jetbrains/kotlin/gradle/plugin/KotlinTarget;Lkotlin/jvm/functions/Function1;)V
|
||||
public static fun compilerOptions (Lorg/jetbrains/kotlin/gradle/plugin/KotlinTarget;Lorg/gradle/api/Action;)V
|
||||
public static fun getDisambiguationClassifier (Lorg/jetbrains/kotlin/gradle/plugin/KotlinTarget;)Ljava/lang/String;
|
||||
public static fun getName (Lorg/jetbrains/kotlin/gradle/plugin/KotlinTarget;)Ljava/lang/String;
|
||||
public static fun mavenPublication (Lorg/jetbrains/kotlin/gradle/plugin/KotlinTarget;Lkotlin/jvm/functions/Function1;)V
|
||||
@@ -1201,6 +1213,8 @@ public final class org/jetbrains/kotlin/gradle/plugin/KotlinTargetWithTests$Comp
|
||||
public final class org/jetbrains/kotlin/gradle/plugin/KotlinTargetWithTests$DefaultImpls {
|
||||
public static fun attributes (Lorg/jetbrains/kotlin/gradle/plugin/KotlinTargetWithTests;Lkotlin/jvm/functions/Function1;)V
|
||||
public static fun attributes (Lorg/jetbrains/kotlin/gradle/plugin/KotlinTargetWithTests;Lorg/gradle/api/Action;)V
|
||||
public static fun compilerOptions (Lorg/jetbrains/kotlin/gradle/plugin/KotlinTargetWithTests;Lkotlin/jvm/functions/Function1;)V
|
||||
public static fun compilerOptions (Lorg/jetbrains/kotlin/gradle/plugin/KotlinTargetWithTests;Lorg/gradle/api/Action;)V
|
||||
public static fun getDisambiguationClassifier (Lorg/jetbrains/kotlin/gradle/plugin/KotlinTargetWithTests;)Ljava/lang/String;
|
||||
public static fun getName (Lorg/jetbrains/kotlin/gradle/plugin/KotlinTargetWithTests;)Ljava/lang/String;
|
||||
public static fun mavenPublication (Lorg/jetbrains/kotlin/gradle/plugin/KotlinTargetWithTests;Lkotlin/jvm/functions/Function1;)V
|
||||
|
||||
+16
@@ -15,6 +15,7 @@ import org.gradle.api.file.FileCollection
|
||||
import org.gradle.api.file.SourceDirectorySet
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptionsDeprecated
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCompileDeprecated
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
|
||||
@@ -58,6 +59,21 @@ interface KotlinCompilation<out T : KotlinCommonOptionsDeprecated> : Named,
|
||||
|
||||
val compilerOptions: HasCompilerOptions<*>
|
||||
|
||||
@Deprecated(
|
||||
"Kotlin compilation level compiler options DSL is not available in this release!",
|
||||
level = DeprecationLevel.ERROR
|
||||
)
|
||||
fun compilerOptions(configure: KotlinCommonCompilerOptions.() -> Unit) {
|
||||
throw UnsupportedOperationException("Kotlin compilation level compiler options DSL is not available in this release!")
|
||||
}
|
||||
@Deprecated(
|
||||
"Kotlin compilation level compiler options DSL is not available in this release!",
|
||||
level = DeprecationLevel.ERROR
|
||||
)
|
||||
fun compilerOptions(configure: Action<KotlinCommonCompilerOptions>) {
|
||||
throw UnsupportedOperationException("Kotlin compilation level compiler options DSL is not available in this release!")
|
||||
}
|
||||
|
||||
@Deprecated(
|
||||
message = "Accessing task instance directly is deprecated",
|
||||
replaceWith = ReplaceWith("compileTaskProvider")
|
||||
|
||||
+15
@@ -64,6 +64,21 @@ interface KotlinTarget : Named, HasAttributes, HasProject, HasMutableExtras {
|
||||
val preset: KotlinTargetPreset<out KotlinTarget>?
|
||||
|
||||
override fun getName(): String = targetName
|
||||
|
||||
@Deprecated(
|
||||
"Kotlin target level compiler options DSL is not available in this release!",
|
||||
level = DeprecationLevel.ERROR
|
||||
)
|
||||
fun compilerOptions(configure: KotlinCommonCompilerOptions.() -> Unit) {
|
||||
throw UnsupportedOperationException("Kotlin target level compiler options DSL is not available in this release!")
|
||||
}
|
||||
@Deprecated(
|
||||
"Kotlin target level compiler options DSL is not available in this release!",
|
||||
level = DeprecationLevel.ERROR
|
||||
)
|
||||
fun compilerOptions(configure: Action<KotlinCommonCompilerOptions>) {
|
||||
throw UnsupportedOperationException("Kotlin target level compiler options DSL is not available in this release!")
|
||||
}
|
||||
}
|
||||
|
||||
interface KotlinTargetWithTests<E : KotlinExecution.ExecutionSource, T : KotlinTargetTestRun<E>> : KotlinTarget {
|
||||
|
||||
+1
@@ -45,6 +45,7 @@ class CompilerOptionsProjectIT : KGPBaseTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Disabled("DSL was demoted to 'internal'; Design is planned for 2.0")
|
||||
@GradleTest
|
||||
@DisplayName("Jvm project target compiler options DSL override project level options")
|
||||
@JvmGradlePluginTests
|
||||
|
||||
@@ -34,6 +34,8 @@ public abstract class org/jetbrains/kotlin/gradle/dsl/KotlinMultiplatformExtensi
|
||||
public fun applyHierarchyTemplate (Lkotlin/jvm/functions/Function1;)V
|
||||
public fun applyHierarchyTemplate (Lorg/jetbrains/kotlin/gradle/plugin/KotlinHierarchyTemplate;)V
|
||||
public fun applyHierarchyTemplate (Lorg/jetbrains/kotlin/gradle/plugin/KotlinHierarchyTemplate;Lkotlin/jvm/functions/Function1;)V
|
||||
public final fun compilerOptions (Lkotlin/jvm/functions/Function1;)V
|
||||
public final fun compilerOptions (Lorg/gradle/api/Action;)V
|
||||
public fun dependencies (Lorg/gradle/api/NamedDomainObjectProvider;Lkotlin/jvm/functions/Function1;)V
|
||||
public fun getAndroidMain (Lorg/gradle/api/NamedDomainObjectContainer;)Lorg/gradle/api/NamedDomainObjectProvider;
|
||||
public fun getAndroidNativeMain (Lorg/gradle/api/NamedDomainObjectContainer;)Lorg/gradle/api/NamedDomainObjectProvider;
|
||||
@@ -738,6 +740,8 @@ public class org/jetbrains/kotlin/gradle/plugin/mpp/external/DecoratedExternalKo
|
||||
public fun <init> (Lorg/jetbrains/kotlin/gradle/plugin/mpp/external/DecoratedExternalKotlinTarget$Delegate;)V
|
||||
public fun attributes (Lkotlin/jvm/functions/Function1;)V
|
||||
public fun attributes (Lorg/gradle/api/Action;)V
|
||||
public fun compilerOptions (Lkotlin/jvm/functions/Function1;)V
|
||||
public fun compilerOptions (Lorg/gradle/api/Action;)V
|
||||
public final fun getApiElementsConfiguration ()Lorg/gradle/api/artifacts/Configuration;
|
||||
public fun getApiElementsConfigurationName ()Ljava/lang/String;
|
||||
public final fun getApiElementsPublishedConfiguration ()Lorg/gradle/api/artifacts/Configuration;
|
||||
|
||||
+2
-2
@@ -252,12 +252,12 @@ abstract class KotlinMultiplatformExtension
|
||||
}
|
||||
|
||||
@ExperimentalKotlinGradlePluginApi
|
||||
internal fun compilerOptions(configure: KotlinCommonCompilerOptions.() -> Unit) {
|
||||
fun compilerOptions(configure: KotlinCommonCompilerOptions.() -> Unit) {
|
||||
configure(compilerOptions)
|
||||
}
|
||||
|
||||
@ExperimentalKotlinGradlePluginApi
|
||||
internal fun compilerOptions(configure: Action<KotlinCommonCompilerOptions>) {
|
||||
fun compilerOptions(configure: Action<KotlinCommonCompilerOptions>) {
|
||||
configure.execute(compilerOptions)
|
||||
}
|
||||
}
|
||||
|
||||
-10
@@ -5,9 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.plugin.mpp
|
||||
|
||||
import org.gradle.api.Action
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformCommonCompilerOptions
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||
@@ -35,13 +33,5 @@ open class KotlinCommonCompilation @Inject internal constructor(compilation: Kot
|
||||
get() = target.project.isKotlinGranularMetadataEnabled && !forceCompilationToKotlinMetadata
|
||||
|
||||
internal var forceCompilationToKotlinMetadata: Boolean = false
|
||||
|
||||
internal fun compilerOptions(configure: KotlinCommonCompilerOptions.() -> Unit) {
|
||||
compilerOptions.configure(configure)
|
||||
}
|
||||
|
||||
internal fun compilerOptions(configure: Action<KotlinCommonCompilerOptions>) {
|
||||
configure.execute(compilerOptions.options)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-11
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.plugin.mpp
|
||||
|
||||
import org.gradle.api.Action
|
||||
import org.gradle.api.Project
|
||||
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
|
||||
@@ -43,16 +42,6 @@ abstract class KotlinMetadataTarget @Inject constructor(
|
||||
internal override val compilerOptions: KotlinCommonCompilerOptions = project.objects
|
||||
.newInstance<KotlinCommonCompilerOptionsDefault>()
|
||||
|
||||
@ExperimentalKotlinGradlePluginApi
|
||||
internal fun compilerOptions(configure: KotlinCommonCompilerOptions.() -> Unit) {
|
||||
configure(compilerOptions)
|
||||
}
|
||||
|
||||
@ExperimentalKotlinGradlePluginApi
|
||||
internal fun compilerOptions(configure: Action<KotlinCommonCompilerOptions>) {
|
||||
configure.execute(compilerOptions)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val METADATA_TARGET_NAME = "metadata"
|
||||
}
|
||||
|
||||
+2
-2
@@ -30,11 +30,11 @@ open class KotlinJvmAndroidCompilation @Inject internal constructor(
|
||||
override val compilerOptions: HasCompilerOptions<KotlinJvmCompilerOptions> =
|
||||
compilation.compilerOptions.castCompilerOptionsType()
|
||||
|
||||
fun compilerOptions(configure: KotlinJvmCompilerOptions.() -> Unit) {
|
||||
internal fun compilerOptions(configure: KotlinJvmCompilerOptions.() -> Unit) {
|
||||
compilerOptions.configure(configure)
|
||||
}
|
||||
|
||||
fun compilerOptions(configure: Action<KotlinJvmCompilerOptions>) {
|
||||
internal fun compilerOptions(configure: Action<KotlinJvmCompilerOptions>) {
|
||||
configure.execute(compilerOptions.options)
|
||||
}
|
||||
|
||||
|
||||
-11
@@ -6,7 +6,6 @@
|
||||
@file:Suppress("PackageDirectoryMismatch") // Old package for compatibility
|
||||
package org.jetbrains.kotlin.gradle.plugin.mpp
|
||||
|
||||
import org.gradle.api.Action
|
||||
import org.gradle.api.NamedDomainObjectContainer
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.file.Directory
|
||||
@@ -64,16 +63,6 @@ abstract class KotlinWithJavaTarget<KotlinOptionsType : KotlinCommonOptions, CO
|
||||
@ExperimentalKotlinGradlePluginApi
|
||||
override val compilerOptions: KotlinJvmCompilerOptions = project.objects
|
||||
.newInstance<KotlinJvmCompilerOptionsDefault>()
|
||||
|
||||
@ExperimentalKotlinGradlePluginApi
|
||||
fun compilerOptions(configure: KotlinJvmCompilerOptions.() -> Unit) {
|
||||
configure(compilerOptions)
|
||||
}
|
||||
|
||||
@ExperimentalKotlinGradlePluginApi
|
||||
fun compilerOptions(configure: Action<KotlinJvmCompilerOptions>) {
|
||||
configure.execute(compilerOptions)
|
||||
}
|
||||
}
|
||||
|
||||
private fun sanitizeFileName(candidate: String): String = candidate.filter { it.isLetterOrDigit() }
|
||||
|
||||
+443
@@ -0,0 +1,443 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle.unitTests
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.jetbrains.kotlin.gradle.dsl.*
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.external.createCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.external.createExternalKotlinTarget
|
||||
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile as KotlinJvmCompileTask
|
||||
import org.jetbrains.kotlin.gradle.tasks.withType
|
||||
import org.jetbrains.kotlin.gradle.util.*
|
||||
import org.jetbrains.kotlin.gradle.utils.named
|
||||
import org.jetbrains.kotlin.test.util.JUnit4Assertions.assertTrue
|
||||
import kotlin.test.Ignore
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class ProjectCompilerOptionsTests {
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
fun nativeTargetCompilerOptionsDSL() {
|
||||
val project = buildProjectWithMPP {
|
||||
with(multiplatformExtension) {
|
||||
linuxX64 {
|
||||
// compilerOptions {
|
||||
// progressiveMode.set(true)
|
||||
// }
|
||||
}
|
||||
|
||||
iosX64 {
|
||||
// compilerOptions {
|
||||
// suppressWarnings.set(true)
|
||||
// }
|
||||
}
|
||||
|
||||
applyDefaultHierarchyTemplate()
|
||||
}
|
||||
}
|
||||
|
||||
project.evaluate()
|
||||
|
||||
assertEquals(true, project.kotlinNativeTask("compileKotlinLinuxX64").compilerOptions.progressiveMode.get())
|
||||
assertEquals(false, project.kotlinNativeTask("compileKotlinLinuxX64").compilerOptions.suppressWarnings.get())
|
||||
assertEquals(true, project.kotlinNativeTask("compileTestKotlinLinuxX64").compilerOptions.progressiveMode.get())
|
||||
assertEquals(false, project.kotlinNativeTask("compileTestKotlinLinuxX64").compilerOptions.suppressWarnings.get())
|
||||
assertEquals(true, project.kotlinNativeTask("compileKotlinIosX64").compilerOptions.suppressWarnings.get())
|
||||
assertEquals(false, project.kotlinNativeTask("compileKotlinIosX64").compilerOptions.progressiveMode.get())
|
||||
assertEquals(true, project.kotlinNativeTask("compileTestKotlinIosX64").compilerOptions.suppressWarnings.get())
|
||||
assertEquals(false, project.kotlinNativeTask("compileTestKotlinIosX64").compilerOptions.progressiveMode.get())
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
fun nativeTaskOverridesTargetOptions() {
|
||||
val project = buildProjectWithMPP {
|
||||
tasks.withType<KotlinCompilationTask<*>>().configureEach {
|
||||
if (it.name == "compileKotlinLinuxX64") {
|
||||
it.compilerOptions.progressiveMode.set(false)
|
||||
}
|
||||
}
|
||||
|
||||
with(multiplatformExtension) {
|
||||
linuxX64 {
|
||||
// compilerOptions {
|
||||
// progressiveMode.set(true)
|
||||
// }
|
||||
}
|
||||
|
||||
applyDefaultHierarchyTemplate()
|
||||
}
|
||||
}
|
||||
|
||||
project.evaluate()
|
||||
|
||||
assertEquals(false, project.kotlinNativeTask("compileKotlinLinuxX64").compilerOptions.progressiveMode.get())
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
fun jsTargetCompilerOptionsDsl() {
|
||||
val project = buildProjectWithMPP {
|
||||
with(multiplatformExtension) {
|
||||
js {
|
||||
// compilerOptions {
|
||||
// suppressWarnings.set(true)
|
||||
// }
|
||||
}
|
||||
|
||||
applyDefaultHierarchyTemplate()
|
||||
}
|
||||
}
|
||||
|
||||
project.evaluate()
|
||||
|
||||
assertEquals(true, project.kotlinJsTask("compileKotlinJs").compilerOptions.suppressWarnings.get())
|
||||
assertEquals(true, project.kotlinJsTask("compileTestKotlinJs").compilerOptions.suppressWarnings.get())
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
fun jsTaskOptionsOverridesTargetOptions() {
|
||||
val project = buildProjectWithMPP {
|
||||
tasks.withType<KotlinCompilationTask<*>>().configureEach {
|
||||
if (it.name == "compileKotlinJs") {
|
||||
it.compilerOptions.suppressWarnings.set(false)
|
||||
}
|
||||
}
|
||||
|
||||
with(multiplatformExtension) {
|
||||
js {
|
||||
// compilerOptions {
|
||||
// suppressWarnings.set(true)
|
||||
// }
|
||||
}
|
||||
|
||||
applyDefaultHierarchyTemplate()
|
||||
}
|
||||
}
|
||||
|
||||
project.evaluate()
|
||||
|
||||
assertEquals(false, project.kotlinJsTask("compileKotlinJs").compilerOptions.suppressWarnings.get())
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
fun metadataTargetDsl() {
|
||||
val project = buildProjectWithMPP {
|
||||
with(multiplatformExtension) {
|
||||
linuxX64()
|
||||
iosX64()
|
||||
iosArm64()
|
||||
|
||||
targets.named("metadata", KotlinMetadataTarget::class.java) {
|
||||
// it.compilerOptions {
|
||||
// progressiveMode.set(true)
|
||||
// }
|
||||
}
|
||||
|
||||
applyDefaultHierarchyTemplate()
|
||||
}
|
||||
}
|
||||
|
||||
project.evaluate()
|
||||
|
||||
assertEquals(true, project.kotlinCommonTask("compileKotlinMetadata").compilerOptions.progressiveMode.get())
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
fun metadataTaskOptionsOverrideTargetOptions() {
|
||||
val project = buildProjectWithMPP {
|
||||
tasks.withType<KotlinCompilationTask<*>>().configureEach {
|
||||
if (it.name == "compileKotlinMetadata") {
|
||||
it.compilerOptions.progressiveMode.set(false)
|
||||
}
|
||||
}
|
||||
|
||||
with(multiplatformExtension) {
|
||||
linuxX64()
|
||||
iosX64()
|
||||
iosArm64()
|
||||
|
||||
targets.named("metadata", KotlinMetadataTarget::class.java) {
|
||||
// it.compilerOptions {
|
||||
// progressiveMode.set(true)
|
||||
// }
|
||||
}
|
||||
|
||||
applyDefaultHierarchyTemplate()
|
||||
}
|
||||
}
|
||||
|
||||
project.evaluate()
|
||||
|
||||
assertEquals(false, project.kotlinCommonTask("compileKotlinMetadata").compilerOptions.progressiveMode.get())
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
fun externalTargetDsl() {
|
||||
val project = buildProjectWithMPP()
|
||||
project.runLifecycleAwareTest {
|
||||
with(multiplatformExtension) {
|
||||
val target = createExternalKotlinTarget<FakeTarget> { defaults() }
|
||||
target.createCompilation<FakeCompilation> { defaults(this@with) }
|
||||
target.createCompilation<FakeCompilation> { defaults(this@with, "test") }
|
||||
|
||||
// target.compilerOptions {
|
||||
// javaParameters.set(true)
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(true, project.kotlinJvmTask("compileKotlinFake").compilerOptions.javaParameters.get())
|
||||
assertEquals(true, project.kotlinJvmTask("compileTestKotlinFake").compilerOptions.javaParameters.get())
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
fun externalTaskOptionsOverridesTargetOptions() {
|
||||
val project = buildProjectWithMPP()
|
||||
project.runLifecycleAwareTest {
|
||||
tasks.withType<KotlinJvmCompileTask>().configureEach {
|
||||
if (it.name == "compileKotlinFake") {
|
||||
it.compilerOptions.javaParameters.set(false)
|
||||
}
|
||||
}
|
||||
|
||||
with(multiplatformExtension) {
|
||||
val target = createExternalKotlinTarget<FakeTarget> { defaults() }
|
||||
target.createCompilation<FakeCompilation> { defaults(this@with) }
|
||||
target.createCompilation<FakeCompilation> { defaults(this@with, "test") }
|
||||
|
||||
// target.compilerOptions {
|
||||
// javaParameters.set(true)
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(false, project.kotlinJvmTask("compileKotlinFake").compilerOptions.javaParameters.get())
|
||||
assertEquals(true, project.kotlinJvmTask("compileTestKotlinFake").compilerOptions.javaParameters.get())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun topLevelOptions() {
|
||||
val project = buildProjectWithMPP()
|
||||
project.runLifecycleAwareTest {
|
||||
with(multiplatformExtension) {
|
||||
compilerOptions {
|
||||
progressiveMode.set(true)
|
||||
}
|
||||
|
||||
jvm()
|
||||
js()
|
||||
iosArm64()
|
||||
linuxX64()
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(true, project.kotlinCommonTask("compileKotlinMetadata").compilerOptions.progressiveMode.get())
|
||||
assertEquals(true, project.kotlinCommonTask("compileNativeMainKotlinMetadata").compilerOptions.progressiveMode.get())
|
||||
assertEquals(true, project.kotlinCommonTask("compileCommonMainKotlinMetadata").compilerOptions.progressiveMode.get())
|
||||
assertEquals(true, project.kotlinJvmTask("compileKotlinJvm").compilerOptions.progressiveMode.get())
|
||||
assertEquals(true, project.kotlinJvmTask("compileTestKotlinJvm").compilerOptions.progressiveMode.get())
|
||||
assertEquals(true, project.kotlinJsTask("compileKotlinJs").compilerOptions.progressiveMode.get())
|
||||
assertEquals(true, project.kotlinJsTask("compileTestKotlinJs").compilerOptions.progressiveMode.get())
|
||||
assertEquals(true, project.kotlinNativeTask("compileKotlinLinuxX64").compilerOptions.progressiveMode.get())
|
||||
assertEquals(true, project.kotlinNativeTask("compileTestKotlinLinuxX64").compilerOptions.progressiveMode.get())
|
||||
assertEquals(true, project.kotlinNativeTask("compileKotlinIosArm64").compilerOptions.progressiveMode.get())
|
||||
assertEquals(true, project.kotlinNativeTask("compileTestKotlinIosArm64").compilerOptions.progressiveMode.get())
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
fun testTargetDslOverridesTopLevelDsl() {
|
||||
val project = buildProjectWithMPP()
|
||||
project.runLifecycleAwareTest {
|
||||
with(multiplatformExtension) {
|
||||
jvm {
|
||||
// compilerOptions {
|
||||
// languageVersion.set(KotlinVersion.KOTLIN_1_8)
|
||||
// }
|
||||
}
|
||||
|
||||
compilerOptions {
|
||||
languageVersion.set(KotlinVersion.KOTLIN_2_0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(KotlinVersion.KOTLIN_1_8, project.kotlinJvmTask("compileKotlinJvm").compilerOptions.languageVersion.orNull)
|
||||
assertEquals(KotlinVersion.KOTLIN_1_8, project.kotlinJvmTask("compileTestKotlinJvm").compilerOptions.languageVersion.orNull)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testTaskDslOverrideTopLevelDsl() {
|
||||
val project = buildProjectWithMPP()
|
||||
project.runLifecycleAwareTest {
|
||||
tasks.withType<KotlinJvmCompileTask>().configureEach {
|
||||
if (it.name == "compileKotlinJvm") {
|
||||
it.compilerOptions.languageVersion.set(KotlinVersion.KOTLIN_1_8)
|
||||
}
|
||||
}
|
||||
|
||||
with(multiplatformExtension) {
|
||||
jvm()
|
||||
|
||||
compilerOptions {
|
||||
languageVersion.set(KotlinVersion.KOTLIN_2_0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(KotlinVersion.KOTLIN_1_8, project.kotlinJvmTask("compileKotlinJvm").compilerOptions.languageVersion.orNull)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testTopLevelDslAlsoConfiguresSharedSourceSets() {
|
||||
val project = buildProjectWithMPP()
|
||||
project.runLifecycleAwareTest {
|
||||
with(multiplatformExtension) {
|
||||
jvm()
|
||||
js()
|
||||
|
||||
compilerOptions {
|
||||
languageVersion.set(KotlinVersion.KOTLIN_2_0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals("2.0", project.multiplatformExtension.sourceSets.getByName("commonTest").languageSettings.languageVersion)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
fun testJvmModuleNameInMppIsConfigured() {
|
||||
val project = buildProjectWithMPP()
|
||||
project.runLifecycleAwareTest {
|
||||
with(multiplatformExtension) {
|
||||
jvm {
|
||||
compilerOptions.moduleName.set("my-custom-module-name")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals("my-custom-module-name", project.kotlinJvmTask("compileKotlinJvm").compilerOptions.moduleName.orNull)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
fun testJsOptionsIsConfigured() {
|
||||
val project = buildProjectWithMPP()
|
||||
project.runLifecycleAwareTest {
|
||||
with(multiplatformExtension) {
|
||||
js {
|
||||
// compilerOptions {
|
||||
// moduleName.set("js-module-name")
|
||||
// freeCompilerArgs.add("-Xstrict-implicit-export-types")
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val kotlinJsCompileTask = project.kotlinJsTask("compileKotlinJs")
|
||||
assertEquals("js-module-name", kotlinJsCompileTask.compilerOptions.moduleName.orNull)
|
||||
assertTrue(
|
||||
kotlinJsCompileTask
|
||||
.compilerOptions
|
||||
.freeCompilerArgs.get()
|
||||
.contains("-Xstrict-implicit-export-types")
|
||||
)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
fun testJsBrowserConfigDoesNotOverrideFreeCompilerArgsFromTarget() {
|
||||
val project = buildProjectWithMPP()
|
||||
project.runLifecycleAwareTest {
|
||||
with(multiplatformExtension) {
|
||||
js {
|
||||
binaries.executable()
|
||||
browser()
|
||||
// compilerOptions {
|
||||
// freeCompilerArgs.addAll("-Xstrict-implicit-export-types", "-Xexplicit-api=warning")
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val kotlinJsCompileTask = project.kotlinJsTask("compileKotlinJs")
|
||||
assertTrue(
|
||||
(kotlinJsCompileTask as Kotlin2JsCompile)
|
||||
.enhancedFreeCompilerArgs.get()
|
||||
.containsAll(listOf("-Xstrict-implicit-export-types", "-Xexplicit-api=warning"))
|
||||
)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
fun testJsLinkTaskAreAlsoConfiguredWithOptionsFromDSL() {
|
||||
val project = buildProjectWithMPP()
|
||||
project.runLifecycleAwareTest {
|
||||
with(multiplatformExtension) {
|
||||
js {
|
||||
nodejs()
|
||||
binaries.library()
|
||||
// compilerOptions {
|
||||
// moduleName.set("my-custom-module")
|
||||
// languageVersion.set(KotlinVersion.KOTLIN_1_8)
|
||||
// apiVersion.set(KotlinVersion.KOTLIN_1_8)
|
||||
// moduleKind.set(JsModuleKind.MODULE_PLAIN)
|
||||
// freeCompilerArgs.addAll("-Xstrict-implicit-export-types", "-Xexplicit-api=warning")
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val jsTasks = listOf(
|
||||
project.kotlinJsTask("compileKotlinJs"),
|
||||
project.kotlinJsTask("compileDevelopmentLibraryKotlinJs"),
|
||||
project.kotlinJsTask("compileProductionLibraryKotlinJs")
|
||||
)
|
||||
jsTasks.forEach { jsTask ->
|
||||
if (jsTask.name == "compileKotlinJs") {
|
||||
// JS IR has different module name from 'compileKotlinJs'
|
||||
assertEquals("my-custom-module", jsTask.compilerOptions.moduleName.orNull)
|
||||
}
|
||||
assertEquals(KotlinVersion.KOTLIN_1_8, jsTask.compilerOptions.languageVersion.orNull)
|
||||
assertEquals(KotlinVersion.KOTLIN_1_8, jsTask.compilerOptions.apiVersion.orNull)
|
||||
assertEquals(JsModuleKind.MODULE_PLAIN, jsTask.compilerOptions.moduleKind.orNull)
|
||||
assertTrue(
|
||||
jsTask.compilerOptions.freeCompilerArgs.get().containsAll(
|
||||
listOf("-Xstrict-implicit-export-types", "-Xexplicit-api=warning")
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun Project.kotlinNativeTask(name: String): KotlinCompilationTask<KotlinNativeCompilerOptions> = tasks
|
||||
.named<KotlinCompilationTask<KotlinNativeCompilerOptions>>(name)
|
||||
.get()
|
||||
|
||||
private fun Project.kotlinJsTask(name: String): KotlinCompilationTask<KotlinJsCompilerOptions> = tasks
|
||||
.named<KotlinCompilationTask<KotlinJsCompilerOptions>>(name)
|
||||
.get()
|
||||
|
||||
private fun Project.kotlinJvmTask(name: String): KotlinCompilationTask<KotlinJvmCompilerOptions> = tasks
|
||||
.named<KotlinCompilationTask<KotlinJvmCompilerOptions>>(name)
|
||||
.get()
|
||||
|
||||
private fun Project.kotlinCommonTask(name: String): KotlinCompilationTask<KotlinCommonCompilerOptions> = tasks
|
||||
.named<KotlinCompilationTask<KotlinCommonCompilerOptions>>(name)
|
||||
.get()
|
||||
}
|
||||
Reference in New Issue
Block a user