[Gradle] Add compiler options DSL for Kotlin targets
Restore compiler options DSL for all Kotlin targets. 'KotlinTarget' interface does not provide any common way to configuring options - this is the responsibility of related plugin extensions. From the hierarchical standpoint of view target DSL overrides options configured in the extension. ^KT-57292 In Progress
This commit is contained in:
committed by
Space Team
parent
e527781772
commit
facc9cdb58
@@ -1159,8 +1159,6 @@ 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;
|
||||
@@ -1184,8 +1182,6 @@ 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
|
||||
@@ -1244,8 +1240,6 @@ 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
|
||||
|
||||
-18
@@ -3,8 +3,6 @@
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@file:Suppress("TYPEALIAS_EXPANSION_DEPRECATION")
|
||||
|
||||
package org.jetbrains.kotlin.gradle.plugin
|
||||
|
||||
import org.gradle.api.Action
|
||||
@@ -17,7 +15,6 @@ import org.gradle.api.publish.maven.MavenPublication
|
||||
import org.jetbrains.kotlin.gradle.PRESETS_API_IS_DEPRECATED_MESSAGE
|
||||
import org.jetbrains.kotlin.gradle.DeprecatedTargetPresetApi
|
||||
import org.jetbrains.kotlin.gradle.InternalKotlinGradlePluginApi
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptionsDeprecated
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinGradlePluginDsl
|
||||
import org.jetbrains.kotlin.tooling.core.HasMutableExtras
|
||||
@@ -66,21 +63,6 @@ interface KotlinTarget : Named, HasAttributes, HasProject, HasMutableExtras {
|
||||
|
||||
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!")
|
||||
}
|
||||
|
||||
@Deprecated(
|
||||
"Accessing 'sourceSets' container on the Kotlin target level DSL is deprecated. " +
|
||||
"Consider configuring 'sourceSets' on the Kotlin extension level.",
|
||||
|
||||
+1
-7
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.gradle
|
||||
import org.gradle.api.logging.LogLevel
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.gradle.testbase.*
|
||||
import org.junit.jupiter.api.Disabled
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import kotlin.io.path.appendText
|
||||
|
||||
@@ -45,7 +44,6 @@ 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
|
||||
@@ -241,7 +239,6 @@ class CompilerOptionsProjectIT : KGPBaseTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Disabled("DSL was demoted to 'internal'; Design is planned for 2.0")
|
||||
@DisplayName("Android target compiler options override project level compiler options")
|
||||
@AndroidGradlePluginTests
|
||||
@GradleAndroidTest
|
||||
@@ -388,7 +385,6 @@ class CompilerOptionsProjectIT : KGPBaseTest() {
|
||||
@DisplayName("KT-57959: should be possible to configure module name in MPP/android")
|
||||
@GradleAndroidTest
|
||||
@AndroidGradlePluginTests
|
||||
@Disabled("DSL was demoted to 'internal'; Design is planned for 2.0")
|
||||
fun mppAndroidModuleName(
|
||||
gradleVersion: GradleVersion,
|
||||
agpVersion: String,
|
||||
@@ -426,7 +422,6 @@ class CompilerOptionsProjectIT : KGPBaseTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Disabled("DSL was demoted to 'internal'; Design is planned for 2.0")
|
||||
@GradleTest
|
||||
@DisplayName("Multiplatform compiler option DSL hierarchy")
|
||||
@JvmGradlePluginTests
|
||||
@@ -503,7 +498,7 @@ class CompilerOptionsProjectIT : KGPBaseTest() {
|
||||
}
|
||||
|
||||
build(":compileKotlinLinuxX64") {
|
||||
extractNativeTasksCommandLineArgumentsFromOutput(":compileKotlinLinuxX64", logLevel = LogLevel.DEBUG) {
|
||||
extractNativeTasksCommandLineArgumentsFromOutput(":compileKotlinLinuxX64") {
|
||||
assertCommandLineArgumentsContain("-language-version", "1.7")
|
||||
assertCommandLineArgumentsContain("-api-version", "1.7")
|
||||
assertCommandLineArgumentsContain("-progressive")
|
||||
@@ -513,7 +508,6 @@ class CompilerOptionsProjectIT : KGPBaseTest() {
|
||||
}
|
||||
|
||||
|
||||
@Disabled("DSL was demoted to 'internal'; Design is planned for 2.0")
|
||||
@DisplayName("KT-61303: Multiplatform/Android module name is changed")
|
||||
@AndroidGradlePluginTests
|
||||
@GradleAndroidTest
|
||||
|
||||
+8
-2
@@ -5,10 +5,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.android
|
||||
|
||||
import org.gradle.api.Action
|
||||
import org.gradle.api.NamedDomainObjectContainer
|
||||
import org.gradle.kotlin.dsl.getByType
|
||||
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
|
||||
import org.jetbrains.kotlin.gradle.dsl.HasConfigurableCompilerOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.external.DecoratedExternalKotlinTarget
|
||||
@@ -17,13 +17,19 @@ data class PrototypeAndroidDsl(
|
||||
var compileSdk: Int
|
||||
)
|
||||
|
||||
@OptIn(ExperimentalKotlinGradlePluginApi::class)
|
||||
class PrototypeAndroidTarget(
|
||||
delegate: Delegate,
|
||||
val androidDsl: PrototypeAndroidDsl
|
||||
) : DecoratedExternalKotlinTarget(delegate) {
|
||||
) : DecoratedExternalKotlinTarget(delegate),
|
||||
HasConfigurableCompilerOptions<KotlinJvmCompilerOptions> {
|
||||
internal val kotlin = super.project.extensions.getByType<KotlinMultiplatformExtension>()
|
||||
|
||||
@Suppress("unchecked_cast")
|
||||
override val compilations: NamedDomainObjectContainer<PrototypeAndroidCompilation>
|
||||
get() = super.compilations as NamedDomainObjectContainer<PrototypeAndroidCompilation>
|
||||
|
||||
@ExperimentalKotlinGradlePluginApi
|
||||
override val compilerOptions: KotlinJvmCompilerOptions
|
||||
get() = super.compilerOptions as KotlinJvmCompilerOptions
|
||||
}
|
||||
@@ -743,18 +743,17 @@ public abstract class org/jetbrains/kotlin/gradle/plugin/mpp/external/DecoratedE
|
||||
public fun <init> (Lorg/jetbrains/kotlin/gradle/plugin/mpp/external/DecoratedExternalKotlinCompilation$Delegate;)V
|
||||
}
|
||||
|
||||
public class org/jetbrains/kotlin/gradle/plugin/mpp/external/DecoratedExternalKotlinTarget : org/jetbrains/kotlin/gradle/plugin/mpp/InternalKotlinTarget {
|
||||
public abstract class org/jetbrains/kotlin/gradle/plugin/mpp/external/DecoratedExternalKotlinTarget : org/jetbrains/kotlin/gradle/plugin/mpp/InternalKotlinTarget {
|
||||
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;
|
||||
public fun getArtifactsTaskName ()Ljava/lang/String;
|
||||
public fun getAttributes ()Lorg/gradle/api/attributes/AttributeContainer;
|
||||
public fun getCompilations ()Lorg/gradle/api/NamedDomainObjectContainer;
|
||||
public fun getCompilerOptions ()Lorg/jetbrains/kotlin/gradle/dsl/KotlinCommonCompilerOptions;
|
||||
public fun getComponents ()Ljava/util/Set;
|
||||
public fun getDisambiguationClassifier ()Ljava/lang/String;
|
||||
public synthetic fun getExtras ()Lorg/jetbrains/kotlin/tooling/core/Extras;
|
||||
|
||||
+12
-5
@@ -5,15 +5,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.internal
|
||||
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.*
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptionsDefault
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptionsHelper
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginLifecycle
|
||||
import org.jetbrains.kotlin.gradle.plugin.await
|
||||
import org.jetbrains.kotlin.gradle.plugin.launch
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.compilerOptions
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.internal
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.external.DecoratedExternalKotlinTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.DefaultLanguageSettingsBuilder
|
||||
import org.jetbrains.kotlin.gradle.utils.newInstance
|
||||
|
||||
@@ -23,7 +22,7 @@ internal fun KotlinMultiplatformExtension.syncCommonOptions(
|
||||
targets.configureEach { target ->
|
||||
KotlinCommonCompilerOptionsHelper.syncOptionsAsConvention(
|
||||
extensionCompilerOptions,
|
||||
target.internal.compilerOptions
|
||||
target.targetCompilerOptions
|
||||
)
|
||||
}
|
||||
|
||||
@@ -45,3 +44,11 @@ internal fun KotlinMultiplatformExtension.syncCommonOptions(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal val KotlinTarget.targetCompilerOptions: KotlinCommonCompilerOptions
|
||||
get() = when (this) {
|
||||
is HasConfigurableCompilerOptions<*> -> compilerOptions
|
||||
// Required for external targets that do not implement 'HasConfigurableCompilerOptions' interface
|
||||
is DecoratedExternalKotlinTarget -> delegate.compilerOptions
|
||||
else -> throw IllegalStateException("'KotlinTarget' type ${this.javaClass} does not allow to configure compiler options!")
|
||||
}
|
||||
|
||||
-2
@@ -37,8 +37,6 @@ abstract class AbstractKotlinTarget(
|
||||
|
||||
override fun getAttributes(): AttributeContainer = attributeContainer
|
||||
|
||||
internal abstract val compilerOptions: KotlinCommonCompilerOptions
|
||||
|
||||
@Deprecated("Scheduled for removal with Kotlin 2.2")
|
||||
override var useDisambiguationClassifierAsSourceSetNamePrefix: Boolean = true
|
||||
internal set
|
||||
|
||||
-11
@@ -10,13 +10,10 @@ import org.gradle.api.NamedDomainObjectContainer
|
||||
import org.gradle.api.publish.maven.MavenPublication
|
||||
import org.gradle.jvm.toolchain.JavaToolchainSpec
|
||||
import org.jetbrains.kotlin.gradle.InternalKotlinGradlePluginApi
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginLifecycle
|
||||
import org.jetbrains.kotlin.gradle.plugin.await
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.external.DecoratedExternalKotlinTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.external.ExternalKotlinTargetImpl
|
||||
import org.jetbrains.kotlin.gradle.utils.extrasStoredFuture
|
||||
import org.jetbrains.kotlin.gradle.utils.getByType
|
||||
import org.jetbrains.kotlin.tooling.core.HasMutableExtras
|
||||
@@ -53,14 +50,6 @@ internal val KotlinTarget.internal: InternalKotlinTarget
|
||||
"KotlinTarget($name) ${this::class} does not implement ${InternalKotlinTarget::class}"
|
||||
)
|
||||
|
||||
internal val InternalKotlinTarget.compilerOptions: KotlinCommonCompilerOptions
|
||||
get() = when (this) {
|
||||
is AbstractKotlinTarget -> compilerOptions
|
||||
is ExternalKotlinTargetImpl -> compilerOptions
|
||||
is DecoratedExternalKotlinTarget -> delegate.compilerOptions
|
||||
else -> throw IllegalStateException("Unexpected 'KotlinTarget' type: ${this.javaClass}")
|
||||
}
|
||||
|
||||
internal val InternalKotlinTarget.isSourcesPublishableFuture by extrasStoredFuture {
|
||||
KotlinPluginLifecycle.Stage.AfterFinaliseDsl.await()
|
||||
isSourcesPublishable
|
||||
|
||||
+4
-3
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.gradle.plugin.mpp
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
|
||||
import org.jetbrains.kotlin.gradle.dsl.HasConfigurableCompilerOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptionsDefault
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||
@@ -19,7 +20,8 @@ import javax.inject.Inject
|
||||
|
||||
abstract class KotlinMetadataTarget @Inject constructor(
|
||||
project: Project,
|
||||
) : KotlinOnlyTarget<KotlinCompilation<*>>(project, KotlinPlatformType.common) {
|
||||
) : KotlinOnlyTarget<KotlinCompilation<*>>(project, KotlinPlatformType.common),
|
||||
HasConfigurableCompilerOptions<KotlinCommonCompilerOptions> {
|
||||
|
||||
override val artifactsTaskName: String
|
||||
// The IDE import looks at this task name to determine the artifact and register the path to the artifact;
|
||||
@@ -37,9 +39,8 @@ abstract class KotlinMetadataTarget @Inject constructor(
|
||||
emptySet()
|
||||
}
|
||||
|
||||
@Suppress("RedundantVisibilityModifier")
|
||||
@ExperimentalKotlinGradlePluginApi
|
||||
internal override val compilerOptions: KotlinCommonCompilerOptions = project.objects
|
||||
override val compilerOptions: KotlinCommonCompilerOptions = project.objects
|
||||
.newInstance<KotlinCommonCompilerOptionsDefault>()
|
||||
|
||||
companion object {
|
||||
|
||||
+3
-2
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl
|
||||
import org.jetbrains.kotlin.gradle.dsl.*
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptionsHelper
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinNativeCompilerOptionsHelper
|
||||
import org.jetbrains.kotlin.gradle.internal.targetCompilerOptions
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.factory.KotlinCompilationImplFactory
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.moduleNameForCompilation
|
||||
@@ -90,13 +91,13 @@ internal object KotlinCompilationCompilerOptionsFromTargetConfigurator : KotlinC
|
||||
commonCompilerOptions: KotlinCommonCompilerOptions
|
||||
) {
|
||||
KotlinCommonCompilerOptionsHelper.syncOptionsAsConvention(
|
||||
target.internal.compilerOptions,
|
||||
target.targetCompilerOptions,
|
||||
commonCompilerOptions
|
||||
)
|
||||
}
|
||||
|
||||
private inline fun <reified T : KotlinCommonCompilerOptions> DecoratedKotlinCompilation<*>.requireTargetCompilerOptionsType(): T {
|
||||
val targetCompilerOptions = compilation.target.internal.compilerOptions
|
||||
val targetCompilerOptions = compilation.target.targetCompilerOptions
|
||||
require(targetCompilerOptions is T) {
|
||||
"${compilation.compilationName} target ${compilation.target.name}:${compilation.target::class.qualifiedName} has incorrect 'compilerOptions' type " +
|
||||
"${targetCompilerOptions::class.qualifiedName}"
|
||||
|
||||
+34
-11
@@ -7,10 +7,12 @@ package org.jetbrains.kotlin.gradle.plugin.mpp.external
|
||||
|
||||
import org.gradle.api.artifacts.Configuration
|
||||
import org.gradle.api.logging.Logger
|
||||
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
|
||||
import org.jetbrains.kotlin.gradle.ExternalKotlinTargetApi
|
||||
import org.jetbrains.kotlin.gradle.dsl.*
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtensionOrNull
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.InternalKotlinTarget
|
||||
|
||||
@@ -23,7 +25,10 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.InternalKotlinTarget
|
||||
* #### Sample
|
||||
*
|
||||
* ```kotlin
|
||||
* class MyCustomJvmTarget(delegate: Delegate): DecoratedExternalKotlinTarget(delegate) {
|
||||
* @OptIn(ExperimentalKotlinGradlePluginApi::class)
|
||||
* class MyCustomJvmTarget(delegate: Delegate): DecoratedExternalKotlinTarget(delegate),
|
||||
* HasConfigurableCompilerOptions<KotlinJvmCompilerOptions> {
|
||||
*
|
||||
* // Some property decorating our target
|
||||
* val myCustomProperty: String = "hello there"
|
||||
*
|
||||
@@ -32,17 +37,9 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.InternalKotlinTarget
|
||||
* get() = super.compilations as NamedDomainObjectContainer<MyCustomCompilationType>
|
||||
*
|
||||
* // Covariant override of target compiler options that should be used to configure all target compilation compiler options
|
||||
* @ExperimentalKotlinGradlePluginApi
|
||||
* override val compilerOptions: KotlinJvmCompilerOptions
|
||||
* get() = super.compilerOptions as KotlinJvmCompilerOptions
|
||||
*
|
||||
* // Optionally follow api exposed in Kotlin built-in targets to configure compiler options
|
||||
* fun compilerOptions(configure: KotlinJvmCompilerOptions.() -> Unit) {
|
||||
* configure(compilerOptions)
|
||||
* }
|
||||
*
|
||||
* fun compilerOptions(configure: Action<KotlinJvmCompilerOptions>) {
|
||||
* configure.execute(compilerOptions)
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
@@ -52,7 +49,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.InternalKotlinTarget
|
||||
* providing a factory function in the [ExternalKotlinTargetDescriptor]
|
||||
*/
|
||||
@ExternalKotlinTargetApi
|
||||
open class DecoratedExternalKotlinTarget internal constructor(
|
||||
abstract class DecoratedExternalKotlinTarget internal constructor(
|
||||
internal val delegate: ExternalKotlinTargetImpl,
|
||||
) : InternalKotlinTarget by delegate {
|
||||
constructor(delegate: Delegate) : this(delegate.impl)
|
||||
@@ -78,6 +75,32 @@ open class DecoratedExternalKotlinTarget internal constructor(
|
||||
val sourcesElementsPublishedConfiguration: Configuration = delegate.sourcesElementsPublishedConfiguration
|
||||
|
||||
internal val logger: Logger = delegate.logger
|
||||
|
||||
/**
|
||||
* Target implementation could override return type to the specific platform type:
|
||||
* - [KotlinPlatformType.common] - should be [KotlinCommonCompilerOptions]
|
||||
* - [KotlinPlatformType.jvm] or [KotlinPlatformType.androidJvm] - could be [KotlinJvmCompilerOptions]
|
||||
* - [KotlinPlatformType.js] or [KotlinPlatformType.wasm] - could be [KotlinJsCompilerOptions]
|
||||
* - [KotlinPlatformType.native] - could be [KotlinNativeCompilerOptions]
|
||||
*
|
||||
* Example:
|
||||
* ```kotlin
|
||||
* @OptIn(ExperimentalKotlinGradlePluginApi::class)
|
||||
* class MyCustomNativeTarget(delegate: Delegate): DecoratedExternalKotlinTarget(delegate),
|
||||
* HasConfigurableCompilerOptions<KotlinNativeCompilerOptions> {
|
||||
*
|
||||
* // Covariant override of target compiler options that should be used to configure
|
||||
* // all target compilation compiler options
|
||||
* @ExperimentalKotlinGradlePluginApi
|
||||
* override val compilerOptions: KotlinNativeCompilerOptions
|
||||
* get() = super.compilerOptions as KotlinNativeCompilerOptions
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@ExperimentalKotlinGradlePluginApi
|
||||
open val compilerOptions: KotlinCommonCompilerOptions = delegate.compilerOptions
|
||||
}
|
||||
|
||||
internal val ExternalKotlinTargetImpl.decoratedInstance: DecoratedExternalKotlinTarget
|
||||
|
||||
+4
-3
@@ -8,13 +8,13 @@ package org.jetbrains.kotlin.gradle.plugin.mpp.external
|
||||
import org.gradle.api.*
|
||||
import org.gradle.api.artifacts.Configuration
|
||||
import org.gradle.api.attributes.AttributeContainer
|
||||
import org.gradle.api.component.SoftwareComponent
|
||||
import org.gradle.api.logging.Logger
|
||||
import org.gradle.api.logging.Logging
|
||||
import org.gradle.api.publish.maven.MavenPublication
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import org.jetbrains.kotlin.gradle.InternalKotlinGradlePluginApi
|
||||
import org.jetbrains.kotlin.gradle.PRESETS_API_IS_DEPRECATED_MESSAGE
|
||||
import org.jetbrains.kotlin.gradle.dsl.HasConfigurableCompilerOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||
@@ -29,7 +29,7 @@ internal class ExternalKotlinTargetImpl internal constructor(
|
||||
override val targetName: String,
|
||||
override val platformType: KotlinPlatformType,
|
||||
override val publishable: Boolean,
|
||||
val compilerOptions: KotlinCommonCompilerOptions,
|
||||
override val compilerOptions: KotlinCommonCompilerOptions,
|
||||
val apiElementsConfiguration: Configuration,
|
||||
val runtimeElementsConfiguration: Configuration,
|
||||
val sourcesElementsConfiguration: Configuration,
|
||||
@@ -38,7 +38,8 @@ internal class ExternalKotlinTargetImpl internal constructor(
|
||||
val sourcesElementsPublishedConfiguration: Configuration,
|
||||
val kotlinTargetComponent: ExternalKotlinTargetComponent,
|
||||
private val artifactsTaskLocator: ArtifactsTaskLocator,
|
||||
) : InternalKotlinTarget {
|
||||
) : InternalKotlinTarget,
|
||||
HasConfigurableCompilerOptions<KotlinCommonCompilerOptions> {
|
||||
|
||||
|
||||
fun interface ArtifactsTaskLocator {
|
||||
|
||||
+4
-13
@@ -11,6 +11,7 @@ import org.gradle.api.artifacts.Configuration
|
||||
import org.gradle.api.attributes.Attribute
|
||||
import org.gradle.api.attributes.AttributeContainer
|
||||
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
|
||||
import org.jetbrains.kotlin.gradle.dsl.HasConfigurableCompilerOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptionsDefault
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
@@ -27,7 +28,8 @@ import javax.inject.Inject
|
||||
abstract class KotlinAndroidTarget @Inject constructor(
|
||||
final override val targetName: String,
|
||||
project: Project,
|
||||
) : AbstractKotlinTarget(project) {
|
||||
) : AbstractKotlinTarget(project),
|
||||
HasConfigurableCompilerOptions<KotlinJvmCompilerOptions> {
|
||||
|
||||
final override val disambiguationClassifier: String = targetName
|
||||
|
||||
@@ -328,22 +330,11 @@ abstract class KotlinAndroidTarget @Inject constructor(
|
||||
attribute: Attribute<*>,
|
||||
): Boolean = attribute.name != "com.android.build.api.attributes.AgpVersionAttr"
|
||||
|
||||
@Suppress("RedundantVisibilityModifier")
|
||||
@ExperimentalKotlinGradlePluginApi
|
||||
internal override val compilerOptions: KotlinJvmCompilerOptions = project.objects
|
||||
override val compilerOptions: KotlinJvmCompilerOptions = project.objects
|
||||
.newInstance<KotlinJvmCompilerOptionsDefault>()
|
||||
.apply {
|
||||
DefaultKotlinJavaToolchain.wireJvmTargetToToolchain(this, project)
|
||||
}
|
||||
|
||||
@ExperimentalKotlinGradlePluginApi
|
||||
internal fun compilerOptions(configure: KotlinJvmCompilerOptions.() -> Unit) {
|
||||
configure(compilerOptions)
|
||||
}
|
||||
|
||||
@ExperimentalKotlinGradlePluginApi
|
||||
internal fun compilerOptions(configure: Action<KotlinJvmCompilerOptions>) {
|
||||
configure.execute(compilerOptions)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-3
@@ -12,8 +12,6 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.MAIN_COMPILATION_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.TEST_COMPILATION_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.compilerOptions
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.internal
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrSingleTargetPreset
|
||||
import org.jetbrains.kotlin.gradle.utils.*
|
||||
|
||||
@@ -85,7 +83,7 @@ open class KotlinJsPlugin: Plugin<Project> {
|
||||
kotlinExtension.sourceSets.maybeCreate(TEST_COMPILATION_NAME)
|
||||
|
||||
kotlinExtension.registerTargetObserver { target ->
|
||||
target?.internal?.compilerOptions?.configureExperimentalTryNext(project)
|
||||
target?.compilerOptions?.configureExperimentalTryNext(project)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -8,6 +8,8 @@ package org.jetbrains.kotlin.gradle.targets.js.dsl
|
||||
import org.gradle.api.Action
|
||||
import org.gradle.api.GradleException
|
||||
import org.gradle.api.NamedDomainObjectContainer
|
||||
import org.jetbrains.kotlin.gradle.dsl.HasConfigurableCompilerOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompilerOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsDce
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.HasBinaries
|
||||
@@ -37,7 +39,9 @@ interface KotlinJsSubTargetContainerDsl : KotlinTarget {
|
||||
interface KotlinJsTargetDsl :
|
||||
KotlinTarget,
|
||||
KotlinTargetWithNodeJsDsl,
|
||||
HasBinaries<KotlinJsBinaryContainer>{
|
||||
HasBinaries<KotlinJsBinaryContainer>,
|
||||
HasConfigurableCompilerOptions<KotlinJsCompilerOptions> {
|
||||
|
||||
var moduleName: String?
|
||||
|
||||
fun browser() = browser { }
|
||||
|
||||
+1
-2
@@ -452,9 +452,8 @@ constructor(
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("RedundantVisibilityModifier")
|
||||
@ExperimentalKotlinGradlePluginApi
|
||||
internal override val compilerOptions: KotlinJsCompilerOptions = project.objects
|
||||
override val compilerOptions: KotlinJsCompilerOptions = project.objects
|
||||
.newInstance<KotlinJsCompilerOptionsDefault>()
|
||||
.apply {
|
||||
configureJsDefaultOptions()
|
||||
|
||||
+2
-14
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.targets.jvm
|
||||
|
||||
import org.gradle.api.Action
|
||||
import org.gradle.api.InvalidUserCodeException
|
||||
import org.gradle.api.NamedDomainObjectContainer
|
||||
import org.gradle.api.Project
|
||||
@@ -48,6 +47,7 @@ import javax.inject.Inject
|
||||
abstract class KotlinJvmTarget @Inject constructor(
|
||||
project: Project,
|
||||
) : KotlinOnlyTarget<KotlinJvmCompilation>(project, KotlinPlatformType.jvm),
|
||||
HasConfigurableCompilerOptions<KotlinJvmCompilerOptions>,
|
||||
KotlinTargetWithTests<JvmClasspathTestRunSource, KotlinJvmTestRun> {
|
||||
|
||||
override val testRuns: NamedDomainObjectContainer<KotlinJvmTestRun> by lazy {
|
||||
@@ -334,9 +334,8 @@ abstract class KotlinJvmTarget @Inject constructor(
|
||||
private fun areRuntimeOrCompileConfigurationsAvailable(): Boolean =
|
||||
GradleVersion.version(project.gradle.gradleVersion) <= GradleVersion.version("6.8.3")
|
||||
|
||||
@Suppress("RedundantVisibilityModifier")
|
||||
@ExperimentalKotlinGradlePluginApi
|
||||
internal override val compilerOptions: KotlinJvmCompilerOptions = project.objects
|
||||
override val compilerOptions: KotlinJvmCompilerOptions = project.objects
|
||||
.newInstance<KotlinJvmCompilerOptionsDefault>()
|
||||
.apply {
|
||||
DefaultKotlinJavaToolchain.wireJvmTargetToToolchain(
|
||||
@@ -344,15 +343,4 @@ abstract class KotlinJvmTarget @Inject constructor(
|
||||
project
|
||||
)
|
||||
}
|
||||
|
||||
@ExperimentalKotlinGradlePluginApi
|
||||
internal fun compilerOptions(configure: KotlinJvmCompilerOptions.() -> Unit) {
|
||||
configure(compilerOptions)
|
||||
}
|
||||
|
||||
@ExperimentalKotlinGradlePluginApi
|
||||
internal fun compilerOptions(configure: Action<KotlinJvmCompilerOptions>) {
|
||||
configure.execute(compilerOptions)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -30,7 +30,8 @@ abstract class KotlinWithJavaTarget<KotlinOptionsType : KotlinCommonOptions, CO
|
||||
override val targetName: String,
|
||||
compilerOptionsFactory: () -> HasCompilerOptions<CO>,
|
||||
kotlinOptionsFactory: (CO) -> KotlinOptionsType
|
||||
) : AbstractKotlinTarget(project) {
|
||||
) : AbstractKotlinTarget(project),
|
||||
HasConfigurableCompilerOptions<KotlinJvmCompilerOptions> {
|
||||
override var disambiguationClassifier: String? = null
|
||||
internal set
|
||||
|
||||
|
||||
+3
-13
@@ -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.attributes.Attribute
|
||||
@@ -34,7 +33,8 @@ import javax.inject.Inject
|
||||
abstract class KotlinNativeTarget @Inject constructor(
|
||||
project: Project,
|
||||
val konanTarget: KonanTarget,
|
||||
) : KotlinTargetWithBinaries<KotlinNativeCompilation, KotlinNativeBinaryContainer>(
|
||||
) : HasConfigurableCompilerOptions<KotlinNativeCompilerOptions>,
|
||||
KotlinTargetWithBinaries<KotlinNativeCompilation, KotlinNativeBinaryContainer>(
|
||||
project,
|
||||
KotlinPlatformType.native
|
||||
) {
|
||||
@@ -100,7 +100,7 @@ abstract class KotlinNativeTarget @Inject constructor(
|
||||
get() = konanTarget.enabledOnCurrentHost
|
||||
|
||||
@ExperimentalKotlinGradlePluginApi
|
||||
internal override val compilerOptions: KotlinNativeCompilerOptions = project.objects
|
||||
override val compilerOptions: KotlinNativeCompilerOptions = project.objects
|
||||
.newInstance<KotlinNativeCompilerOptionsDefault>()
|
||||
.apply {
|
||||
moduleName.convention(
|
||||
@@ -110,16 +110,6 @@ abstract class KotlinNativeTarget @Inject constructor(
|
||||
)
|
||||
}
|
||||
|
||||
@ExperimentalKotlinGradlePluginApi
|
||||
internal fun compilerOptions(configure: KotlinNativeCompilerOptions.() -> Unit) {
|
||||
configure(compilerOptions)
|
||||
}
|
||||
|
||||
@ExperimentalKotlinGradlePluginApi
|
||||
internal fun compilerOptions(configure: Action<KotlinNativeCompilerOptions>) {
|
||||
configure.execute(compilerOptions)
|
||||
}
|
||||
|
||||
// User-visible constants
|
||||
val DEBUG = NativeBuildType.DEBUG
|
||||
val RELEASE = NativeBuildType.RELEASE
|
||||
|
||||
+158
-57
@@ -24,21 +24,20 @@ import kotlin.test.assertEquals
|
||||
|
||||
class ProjectCompilerOptionsTests {
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
fun nativeTargetCompilerOptionsDSL() {
|
||||
val project = buildProjectWithMPP {
|
||||
with(multiplatformExtension) {
|
||||
linuxX64 {
|
||||
// compilerOptions {
|
||||
// progressiveMode.set(true)
|
||||
// }
|
||||
compilerOptions {
|
||||
progressiveMode.set(true)
|
||||
}
|
||||
}
|
||||
|
||||
iosX64 {
|
||||
// compilerOptions {
|
||||
// suppressWarnings.set(true)
|
||||
// }
|
||||
compilerOptions {
|
||||
suppressWarnings.set(true)
|
||||
}
|
||||
}
|
||||
|
||||
applyDefaultHierarchyTemplate()
|
||||
@@ -57,7 +56,6 @@ class ProjectCompilerOptionsTests {
|
||||
assertEquals(false, project.kotlinNativeTask("compileTestKotlinIosX64").compilerOptions.progressiveMode.get())
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
fun nativeTaskOverridesTargetOptions() {
|
||||
val project = buildProjectWithMPP {
|
||||
@@ -69,9 +67,9 @@ class ProjectCompilerOptionsTests {
|
||||
|
||||
with(multiplatformExtension) {
|
||||
linuxX64 {
|
||||
// compilerOptions {
|
||||
// progressiveMode.set(true)
|
||||
// }
|
||||
compilerOptions {
|
||||
progressiveMode.set(true)
|
||||
}
|
||||
}
|
||||
|
||||
applyDefaultHierarchyTemplate()
|
||||
@@ -83,15 +81,105 @@ class ProjectCompilerOptionsTests {
|
||||
assertEquals(false, project.kotlinNativeTask("compileKotlinLinuxX64").compilerOptions.progressiveMode.get())
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
fun nativeLanguageSettingsOverridesTargetOptions() {
|
||||
val project = buildProjectWithMPP {
|
||||
with(multiplatformExtension) {
|
||||
linuxX64 {
|
||||
compilerOptions {
|
||||
progressiveMode.set(true)
|
||||
}
|
||||
}
|
||||
|
||||
applyDefaultHierarchyTemplate()
|
||||
|
||||
sourceSets.getByName("linuxX64Main").languageSettings {
|
||||
progressiveMode = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
project.evaluate()
|
||||
|
||||
assertEquals(false, project.kotlinNativeTask("compileKotlinLinuxX64").compilerOptions.progressiveMode.get())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun jvmTargetCompilerOptionsDSL() {
|
||||
val project = buildProjectWithMPP {
|
||||
with(multiplatformExtension) {
|
||||
jvm {
|
||||
compilerOptions {
|
||||
noJdk.set(true)
|
||||
}
|
||||
}
|
||||
|
||||
applyDefaultHierarchyTemplate()
|
||||
}
|
||||
}
|
||||
|
||||
project.evaluate()
|
||||
|
||||
assertEquals(true, project.kotlinJvmTask("compileKotlinJvm").compilerOptions.noJdk.get())
|
||||
assertEquals(true, project.kotlinJvmTask("compileTestKotlinJvm").compilerOptions.noJdk.get())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun jvmTaskOverridesTargetOptions() {
|
||||
val project = buildProjectWithMPP {
|
||||
tasks.withType<KotlinCompilationTask<*>>().configureEach {
|
||||
if (it.name == "compileKotlinJvm") {
|
||||
it.compilerOptions.progressiveMode.set(false)
|
||||
}
|
||||
}
|
||||
|
||||
with(multiplatformExtension) {
|
||||
jvm {
|
||||
compilerOptions {
|
||||
progressiveMode.set(true)
|
||||
}
|
||||
}
|
||||
|
||||
applyDefaultHierarchyTemplate()
|
||||
}
|
||||
}
|
||||
|
||||
project.evaluate()
|
||||
|
||||
assertEquals(false, project.kotlinJvmTask("compileKotlinJvm").compilerOptions.progressiveMode.get())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun jvmLanguageSettingsOverridesTargetOptions() {
|
||||
val project = buildProjectWithMPP {
|
||||
with(multiplatformExtension) {
|
||||
jvm {
|
||||
compilerOptions {
|
||||
progressiveMode.set(true)
|
||||
}
|
||||
}
|
||||
|
||||
applyDefaultHierarchyTemplate()
|
||||
|
||||
sourceSets.getByName("jvmMain").languageSettings {
|
||||
progressiveMode = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
project.evaluate()
|
||||
|
||||
assertEquals(false, project.kotlinJvmTask("compileKotlinJvm").compilerOptions.progressiveMode.get())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun jsTargetCompilerOptionsDsl() {
|
||||
val project = buildProjectWithMPP {
|
||||
with(multiplatformExtension) {
|
||||
js {
|
||||
// compilerOptions {
|
||||
// suppressWarnings.set(true)
|
||||
// }
|
||||
compilerOptions {
|
||||
suppressWarnings.set(true)
|
||||
}
|
||||
}
|
||||
|
||||
applyDefaultHierarchyTemplate()
|
||||
@@ -104,7 +192,6 @@ class ProjectCompilerOptionsTests {
|
||||
assertEquals(true, project.kotlinJsTask("compileTestKotlinJs").compilerOptions.suppressWarnings.get())
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
fun jsTaskOptionsOverridesTargetOptions() {
|
||||
val project = buildProjectWithMPP {
|
||||
@@ -116,9 +203,9 @@ class ProjectCompilerOptionsTests {
|
||||
|
||||
with(multiplatformExtension) {
|
||||
js {
|
||||
// compilerOptions {
|
||||
// suppressWarnings.set(true)
|
||||
// }
|
||||
compilerOptions {
|
||||
suppressWarnings.set(true)
|
||||
}
|
||||
}
|
||||
|
||||
applyDefaultHierarchyTemplate()
|
||||
@@ -130,7 +217,29 @@ class ProjectCompilerOptionsTests {
|
||||
assertEquals(false, project.kotlinJsTask("compileKotlinJs").compilerOptions.suppressWarnings.get())
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
fun jsLanguageSettingsOverridesTargetOptions() {
|
||||
val project = buildProjectWithMPP {
|
||||
with(multiplatformExtension) {
|
||||
js {
|
||||
compilerOptions {
|
||||
progressiveMode.set(true)
|
||||
}
|
||||
}
|
||||
|
||||
applyDefaultHierarchyTemplate()
|
||||
|
||||
sourceSets.getByName("jsMain").languageSettings {
|
||||
progressiveMode = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
project.evaluate()
|
||||
|
||||
assertEquals(false, project.kotlinJsTask("compileKotlinJs").compilerOptions.progressiveMode.get())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun metadataTargetDsl() {
|
||||
val project = buildProjectWithMPP {
|
||||
@@ -140,9 +249,9 @@ class ProjectCompilerOptionsTests {
|
||||
iosArm64()
|
||||
|
||||
targets.named("metadata", KotlinMetadataTarget::class.java) {
|
||||
// it.compilerOptions {
|
||||
// progressiveMode.set(true)
|
||||
// }
|
||||
it.compilerOptions {
|
||||
progressiveMode.set(true)
|
||||
}
|
||||
}
|
||||
|
||||
applyDefaultHierarchyTemplate()
|
||||
@@ -154,7 +263,6 @@ class ProjectCompilerOptionsTests {
|
||||
assertEquals(true, project.kotlinCommonTask("compileKotlinMetadata").compilerOptions.progressiveMode.get())
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
fun metadataTaskOptionsOverrideTargetOptions() {
|
||||
val project = buildProjectWithMPP {
|
||||
@@ -170,9 +278,9 @@ class ProjectCompilerOptionsTests {
|
||||
iosArm64()
|
||||
|
||||
targets.named("metadata", KotlinMetadataTarget::class.java) {
|
||||
// it.compilerOptions {
|
||||
// progressiveMode.set(true)
|
||||
// }
|
||||
it.compilerOptions {
|
||||
progressiveMode.set(true)
|
||||
}
|
||||
}
|
||||
|
||||
applyDefaultHierarchyTemplate()
|
||||
@@ -184,7 +292,6 @@ class ProjectCompilerOptionsTests {
|
||||
assertEquals(false, project.kotlinCommonTask("compileKotlinMetadata").compilerOptions.progressiveMode.get())
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
fun externalTargetDsl() {
|
||||
val project = buildProjectWithMPP()
|
||||
@@ -194,9 +301,9 @@ class ProjectCompilerOptionsTests {
|
||||
target.createCompilation<FakeCompilation> { defaults(this@with) }
|
||||
target.createCompilation<FakeCompilation> { defaults(this@with, "test") }
|
||||
|
||||
// target.compilerOptions {
|
||||
// javaParameters.set(true)
|
||||
// }
|
||||
target.compilerOptions {
|
||||
javaParameters.set(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +311,6 @@ class ProjectCompilerOptionsTests {
|
||||
assertEquals(true, project.kotlinJvmTask("compileTestKotlinFake").compilerOptions.javaParameters.get())
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
fun externalTaskOptionsOverridesTargetOptions() {
|
||||
val project = buildProjectWithMPP()
|
||||
@@ -220,9 +326,9 @@ class ProjectCompilerOptionsTests {
|
||||
target.createCompilation<FakeCompilation> { defaults(this@with) }
|
||||
target.createCompilation<FakeCompilation> { defaults(this@with, "test") }
|
||||
|
||||
// target.compilerOptions {
|
||||
// javaParameters.set(true)
|
||||
// }
|
||||
target.compilerOptions {
|
||||
javaParameters.set(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,16 +365,15 @@ class ProjectCompilerOptionsTests {
|
||||
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_1_8)
|
||||
}
|
||||
}
|
||||
|
||||
compilerOptions {
|
||||
@@ -320,7 +425,6 @@ class ProjectCompilerOptionsTests {
|
||||
assertEquals("2.0", project.multiplatformExtension.sourceSets.getByName("commonTest").languageSettings.languageVersion)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
fun testJvmModuleNameInMppIsConfigured() {
|
||||
val project = buildProjectWithMPP()
|
||||
@@ -335,17 +439,16 @@ class ProjectCompilerOptionsTests {
|
||||
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")
|
||||
// }
|
||||
compilerOptions {
|
||||
moduleName.set("js-module-name")
|
||||
freeCompilerArgs.add("-Xstrict-implicit-export-types")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -360,7 +463,6 @@ class ProjectCompilerOptionsTests {
|
||||
)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
fun testJsBrowserConfigDoesNotOverrideFreeCompilerArgsFromTarget() {
|
||||
val project = buildProjectWithMPP()
|
||||
@@ -369,9 +471,9 @@ class ProjectCompilerOptionsTests {
|
||||
js {
|
||||
binaries.executable()
|
||||
browser()
|
||||
// compilerOptions {
|
||||
// freeCompilerArgs.addAll("-Xstrict-implicit-export-types", "-Xexplicit-api=warning")
|
||||
// }
|
||||
compilerOptions {
|
||||
freeCompilerArgs.addAll("-Xstrict-implicit-export-types", "-Xexplicit-api=warning")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -384,7 +486,6 @@ class ProjectCompilerOptionsTests {
|
||||
)
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
fun testJsLinkTaskAreAlsoConfiguredWithOptionsFromDSL() {
|
||||
val project = buildProjectWithMPP()
|
||||
@@ -393,13 +494,13 @@ class ProjectCompilerOptionsTests {
|
||||
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")
|
||||
// }
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-1
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.gradle.util
|
||||
|
||||
import org.gradle.api.NamedDomainObjectContainer
|
||||
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
|
||||
import org.jetbrains.kotlin.gradle.dsl.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.HasCompilerOptions
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||
@@ -20,11 +21,16 @@ class FakeCompilation(delegate: Delegate) : DecoratedExternalKotlinCompilation(d
|
||||
get() = super.compilerOptions as HasCompilerOptions<KotlinJvmCompilerOptions>
|
||||
}
|
||||
|
||||
class FakeTarget(delegate: Delegate) : DecoratedExternalKotlinTarget(delegate) {
|
||||
class FakeTarget(delegate: Delegate) : DecoratedExternalKotlinTarget(delegate),
|
||||
HasConfigurableCompilerOptions<KotlinJvmCompilerOptions> {
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override val compilations: NamedDomainObjectContainer<FakeCompilation>
|
||||
get() = super.compilations as NamedDomainObjectContainer<FakeCompilation>
|
||||
|
||||
@ExperimentalKotlinGradlePluginApi
|
||||
override val compilerOptions: KotlinJvmCompilerOptions
|
||||
get() = super.compilerOptions as KotlinJvmCompilerOptions
|
||||
}
|
||||
|
||||
fun ExternalKotlinTargetDescriptorBuilder<FakeTarget>.defaults() {
|
||||
|
||||
Reference in New Issue
Block a user