diff --git a/libraries/tools/kotlin-gradle-plugin-api/api/kotlin-gradle-plugin-api.api b/libraries/tools/kotlin-gradle-plugin-api/api/kotlin-gradle-plugin-api.api index 8742f51c267..3015561a19f 100644 --- a/libraries/tools/kotlin-gradle-plugin-api/api/kotlin-gradle-plugin-api.api +++ b/libraries/tools/kotlin-gradle-plugin-api/api/kotlin-gradle-plugin-api.api @@ -1002,18 +1002,18 @@ public final class org/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerType$Compa } public abstract interface class org/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerTypeHolder { - public abstract fun getBOTH ()Lorg/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerType; + public abstract synthetic fun getBOTH ()Lorg/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerType; public abstract fun getCompilerTypeFromProperties ()Lorg/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerType; public abstract fun getDefaultJsCompilerType ()Lorg/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerType; public abstract fun getIR ()Lorg/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerType; - public abstract fun getLEGACY ()Lorg/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerType; + public abstract synthetic fun getLEGACY ()Lorg/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerType; } public final class org/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerTypeHolder$DefaultImpls { - public static fun getBOTH (Lorg/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerTypeHolder;)Lorg/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerType; + public static synthetic fun getBOTH (Lorg/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerTypeHolder;)Lorg/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerType; public static fun getDefaultJsCompilerType (Lorg/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerTypeHolder;)Lorg/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerType; public static fun getIR (Lorg/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerTypeHolder;)Lorg/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerType; - public static fun getLEGACY (Lorg/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerTypeHolder;)Lorg/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerType; + public static synthetic fun getLEGACY (Lorg/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerTypeHolder;)Lorg/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerType; } public final class org/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerTypeKt { diff --git a/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerTypeHolder.kt b/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerTypeHolder.kt index c7e6ef85446..7a45da3798e 100644 --- a/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerTypeHolder.kt +++ b/libraries/tools/kotlin-gradle-plugin-api/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerTypeHolder.kt @@ -12,17 +12,17 @@ interface KotlinJsCompilerTypeHolder { val compilerTypeFromProperties: KotlinJsCompilerType? val defaultJsCompilerType: KotlinJsCompilerType - get() = compilerTypeFromProperties ?: KotlinJsCompilerType.IR + get() = KotlinJsCompilerType.IR // Necessary to get rid of KotlinJsCompilerType import in build script - @Deprecated("Legacy compiler is deprecated. Migrate your project to the new IR-based compiler") + @Deprecated("Legacy compiler is deprecated. Migrate your project to the new IR-based compiler", level = DeprecationLevel.HIDDEN) val LEGACY: KotlinJsCompilerType get() = KotlinJsCompilerType.LEGACY val IR: KotlinJsCompilerType get() = KotlinJsCompilerType.IR - @Deprecated("Legacy compiler is deprecated. Migrate your project to the new IR-based compiler") + @Deprecated("Legacy compiler is deprecated. Migrate your project to the new IR-based compiler", level = DeprecationLevel.HIDDEN) val BOTH: KotlinJsCompilerType get() = KotlinJsCompilerType.BOTH } \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-android/app/build.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-android/app/build.gradle index c31c726b531..3dac7b0302f 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-android/app/build.gradle +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-android/app/build.gradle @@ -65,7 +65,7 @@ kotlin { targets { fromPreset(presets.android, 'androidApp') fromPreset(presets.jvm, 'jvmApp') - fromPreset(presets.jsIr, 'jsApp') + fromPreset(presets.js, 'jsApp') } } diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-android/lib/build.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-android/lib/build.gradle index 4d4c9b8d61a..bdb75bb149b 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-android/lib/build.gradle +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/resources/testProject/new-mpp-android/lib/build.gradle @@ -87,7 +87,7 @@ kotlin { publishAllLibraryVariants() } fromPreset(presets.jvm, 'jvmLib') - fromPreset(presets.jsIr, 'jsLib') + fromPreset(presets.js, 'jsLib') } } diff --git a/libraries/tools/kotlin-gradle-plugin/api/kotlin-gradle-plugin.api b/libraries/tools/kotlin-gradle-plugin/api/kotlin-gradle-plugin.api index 9c746f7889d..0d51607098d 100644 --- a/libraries/tools/kotlin-gradle-plugin/api/kotlin-gradle-plugin.api +++ b/libraries/tools/kotlin-gradle-plugin/api/kotlin-gradle-plugin.api @@ -40,7 +40,7 @@ public abstract class org/jetbrains/kotlin/gradle/dsl/KotlinMultiplatformExtensi public fun getAndroidNativeTest (Lorg/gradle/api/NamedDomainObjectContainer;)Lorg/gradle/api/NamedDomainObjectProvider; public fun getAppleMain (Lorg/gradle/api/NamedDomainObjectContainer;)Lorg/gradle/api/NamedDomainObjectProvider; public fun getAppleTest (Lorg/gradle/api/NamedDomainObjectContainer;)Lorg/gradle/api/NamedDomainObjectProvider; - public fun getBOTH ()Lorg/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerType; + public synthetic fun getBOTH ()Lorg/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerType; public fun getCommonMain (Lorg/gradle/api/NamedDomainObjectContainer;)Lorg/gradle/api/NamedDomainObjectProvider; public fun getCommonTest (Lorg/gradle/api/NamedDomainObjectContainer;)Lorg/gradle/api/NamedDomainObjectProvider; public fun getCompilerTypeFromProperties ()Lorg/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerType; @@ -52,7 +52,7 @@ public abstract class org/jetbrains/kotlin/gradle/dsl/KotlinMultiplatformExtensi public fun getJsTest (Lorg/gradle/api/NamedDomainObjectContainer;)Lorg/gradle/api/NamedDomainObjectProvider; public fun getJvmMain (Lorg/gradle/api/NamedDomainObjectContainer;)Lorg/gradle/api/NamedDomainObjectProvider; public fun getJvmTest (Lorg/gradle/api/NamedDomainObjectContainer;)Lorg/gradle/api/NamedDomainObjectProvider; - public fun getLEGACY ()Lorg/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerType; + public synthetic fun getLEGACY ()Lorg/jetbrains/kotlin/gradle/plugin/KotlinJsCompilerType; public fun getLinuxMain (Lorg/gradle/api/NamedDomainObjectContainer;)Lorg/gradle/api/NamedDomainObjectProvider; public fun getLinuxTest (Lorg/gradle/api/NamedDomainObjectContainer;)Lorg/gradle/api/NamedDomainObjectProvider; public fun getMacosMain (Lorg/gradle/api/NamedDomainObjectContainer;)Lorg/gradle/api/NamedDomainObjectProvider; diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinMultiplatformExtension.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinMultiplatformExtension.kt index 450e958fe8c..edcc3a55c6c 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinMultiplatformExtension.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinMultiplatformExtension.kt @@ -16,7 +16,6 @@ import org.jetbrains.kotlin.gradle.PRESETS_API_IS_DEPRECATED_MESSAGE import org.jetbrains.kotlin.gradle.internal.syncCommonOptions import org.jetbrains.kotlin.gradle.plugin.* import org.jetbrains.kotlin.gradle.plugin.KotlinPluginLifecycle.Stage.AfterFinaliseDsl -import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.Companion.kotlinPropertiesProvider import org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinToolingDiagnostics import org.jetbrains.kotlin.gradle.plugin.diagnostics.reportDiagnostic import org.jetbrains.kotlin.gradle.plugin.hierarchy.KotlinHierarchyDslImpl @@ -46,13 +45,14 @@ abstract class KotlinMultiplatformExtension final override val targets: NamedDomainObjectCollection = project.container(KotlinTarget::class.java) + @Deprecated("Because only IR compiler is left, no more necessary to know about compiler type in properties") + override val compilerTypeFromProperties: KotlinJsCompilerType? = null + internal suspend fun awaitTargets(): NamedDomainObjectCollection { AfterFinaliseDsl.await() return targets } - override val compilerTypeFromProperties: KotlinJsCompilerType? = project.kotlinPropertiesProvider.jsCompiler - private val presetExtension = project.objects.newInstance( DefaultTargetsFromPresetExtension::class.java, { this }, diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinProjectExtension.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinProjectExtension.kt index 8f7a64d0b7f..b822494e871 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinProjectExtension.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinProjectExtension.kt @@ -17,18 +17,14 @@ import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi import org.jetbrains.kotlin.gradle.internal.KOTLIN_BUILD_TOOLS_API_IMPL import org.jetbrains.kotlin.gradle.internal.KOTLIN_MODULE_GROUP import org.jetbrains.kotlin.gradle.plugin.* -import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.Companion.kotlinPropertiesProvider import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsSingleTargetPreset import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinWithJavaTarget -import org.jetbrains.kotlin.gradle.targets.js.calculateJsCompilerType import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrSingleTargetPreset import org.jetbrains.kotlin.gradle.tasks.CompileUsingKotlinDaemon import org.jetbrains.kotlin.gradle.tasks.withType import org.jetbrains.kotlin.gradle.utils.castIsolatedKotlinPluginClassLoaderAware import org.jetbrains.kotlin.gradle.utils.configureExperimentalTryK2 -import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName import org.jetbrains.kotlin.konan.target.CompilerOutputKind import javax.inject.Inject import kotlin.reflect.KClass @@ -226,10 +222,11 @@ abstract class KotlinJsProjectExtension(project: Project) : KotlinJsCompilerTypeHolder { lateinit var irPreset: KotlinJsIrSingleTargetPreset - lateinit var legacyPreset: KotlinJsSingleTargetPreset - private val targetSetObservers = mutableListOf<(KotlinJsTargetDsl?) -> Unit>() + @Deprecated("Because only IR compiler is left, no more necessary to know about compiler type in properties") + override val compilerTypeFromProperties: KotlinJsCompilerType? = null + // target is public property // Users can write kotlin.target and it should work // So call of target should init default configuration @@ -244,41 +241,6 @@ abstract class KotlinJsProjectExtension(project: Project) : targetSetObservers.add(observer) } - companion object { - internal fun warnAboutDeprecatedCompiler(project: Project, compilerType: KotlinJsCompilerType) { - if (PropertiesProvider(project).jsCompilerNoWarn) return - val logger = project.logger - when (compilerType) { - KotlinJsCompilerType.LEGACY -> logger.warn(LEGACY_DEPRECATED) - KotlinJsCompilerType.IR -> {} - KotlinJsCompilerType.BOTH -> logger.warn(BOTH_DEPRECATED) - } - } - - private val LEGACY_DEPRECATED = - """ - | - |========== - |This project currently uses the Kotlin/JS Legacy compiler backend, which has been deprecated and will be removed in a future release. - | - |Please migrate the project to the new IR-based compiler (https://kotl.in/jsir). - |========== - | - """.trimMargin() - - private val BOTH_DEPRECATED = - """ - | - |========== - |This project currently uses Both mode, which requires the Kotlin/JS Legacy compiler backend. - |This backend has been deprecated and will be removed in a future release. - | - |Please migrate the project to the new IR-based compiler (https://kotl.in/jsir). - |========== - | - """.trimMargin() - } - @Deprecated("Use js() instead", ReplaceWith("js()")) @Suppress("DEPRECATION") override val target: KotlinJsTargetDsl @@ -289,49 +251,14 @@ abstract class KotlinJsProjectExtension(project: Project) : return _target!! } - override val compilerTypeFromProperties: KotlinJsCompilerType? = project.kotlinPropertiesProvider.jsCompiler - @Suppress("DEPRECATION") private fun jsInternal( compiler: KotlinJsCompilerType? = null, - body: KotlinJsTargetDsl.() -> Unit + body: KotlinJsTargetDsl.() -> Unit, ): KotlinJsTargetDsl { - if (_target != null) { - val previousCompilerType = _target!!.calculateJsCompilerType() - check(compiler == null || previousCompilerType == compiler) { - "You already registered Kotlin/JS target with another compiler: ${previousCompilerType.lowerName}" - } - } - if (_target == null) { - val compilerOrFromProperties = compiler ?: compilerTypeFromProperties - val compilerOrDefault = compilerOrFromProperties ?: defaultJsCompilerType - warnAboutDeprecatedCompiler(project, compilerOrDefault) - val target: KotlinJsTargetDsl = when (compilerOrDefault) { - KotlinJsCompilerType.LEGACY -> legacyPreset - .also { - it.irPreset = null - } - .createTargetInternal("js") - - KotlinJsCompilerType.IR -> irPreset - .also { - it.mixedMode = false - } - .createTargetInternal("js") - - KotlinJsCompilerType.BOTH -> legacyPreset - .also { - irPreset.mixedMode = true - it.irPreset = irPreset - } - .createTargetInternal( - lowerCamelCaseName( - "js", - LEGACY.lowerName - ) - ) - } + val target: KotlinJsTargetDsl = irPreset + .createTargetInternal("js") this._target = target @@ -345,19 +272,19 @@ abstract class KotlinJsProjectExtension(project: Project) : fun js( compiler: KotlinJsCompilerType = defaultJsCompilerType, - body: KotlinJsTargetDsl.() -> Unit = { } + body: KotlinJsTargetDsl.() -> Unit = { }, ): KotlinJsTargetDsl = jsInternal(compiler, body) fun js( compiler: String, - body: KotlinJsTargetDsl.() -> Unit = { } + body: KotlinJsTargetDsl.() -> Unit = { }, ): KotlinJsTargetDsl = js( KotlinJsCompilerType.byArgument(compiler), body ) fun js( - body: KotlinJsTargetDsl.() -> Unit = { } + body: KotlinJsTargetDsl.() -> Unit = { }, ) = jsInternal(body = body) fun js() = js { } @@ -396,7 +323,7 @@ abstract class KotlinCommonProjectExtension(project: Project) : KotlinSingleJava internal set open fun target( - body: KotlinWithJavaTarget.() -> Unit + body: KotlinWithJavaTarget.() -> Unit, ) = target.run(body) } diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinTargetContainerWithJsPresetFunctions.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinTargetContainerWithJsPresetFunctions.kt index 97fdf4304bf..b254e682f8d 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinTargetContainerWithJsPresetFunctions.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinTargetContainerWithJsPresetFunctions.kt @@ -6,12 +6,9 @@ package org.jetbrains.kotlin.gradle.dsl import org.gradle.api.Action -import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension.Companion.warnAboutDeprecatedCompiler import org.jetbrains.kotlin.gradle.plugin.* import org.jetbrains.kotlin.gradle.targets.android.internal.InternalKotlinTargetPreset -import org.jetbrains.kotlin.gradle.targets.js.calculateJsCompilerType import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl -import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName @KotlinGradlePluginDsl interface KotlinTargetContainerWithJsPresetFunctions : @@ -84,72 +81,12 @@ private fun KotlinTargetContainerWithJsPresetFunctions.jsInternal( compiler: KotlinJsCompilerType? = null, configure: KotlinJsTargetDsl.() -> Unit ): KotlinJsTargetDsl { - val existingTarget = getExistingTarget(name, compiler) - - val kotlinJsCompilerType = (compiler - ?: existingTarget?.calculateJsCompilerType()) - - val compilerOrDefault = kotlinJsCompilerType - ?: defaultJsCompilerType - - val targetName = getTargetName(name, compilerOrDefault) - - if (existingTarget != null) { - val previousCompilerType = existingTarget.calculateJsCompilerType() - check(compiler == null || previousCompilerType == compiler) { - "You already registered Kotlin/JS target '$targetName' with another compiler: ${previousCompilerType.lowerName}" - } - } - @Suppress("UNCHECKED_CAST", "DEPRECATION") return configureOrCreate( - targetName, + name, presets.getByName( - lowerCamelCaseName( - "js", - if (compilerOrDefault == KotlinJsCompilerType.LEGACY) null else compilerOrDefault.lowerName - ) + "js" ) as InternalKotlinTargetPreset, configure - ).also { target -> - warnAboutDeprecatedCompiler(target.project, compilerOrDefault) - } -} - -// Try to find existing target with exact name -// and with append suffix Legacy in case when compiler for found target is BOTH, -// and removed suffix Legacy in case when current compiler is BOTH -private fun KotlinTargetContainerWithJsPresetFunctions.getExistingTarget( - name: String, - compiler: KotlinJsCompilerType? -): KotlinJsTargetDsl? { - - fun getPreviousTarget( - targetName: String, - currentBoth: Boolean - ): KotlinJsTargetDsl? { - val singleTarget = targets.findByName( - targetName - ) as KotlinJsTargetDsl? - - return singleTarget?.let { - val previousCompiler = it.calculateJsCompilerType() - if (compiler == KotlinJsCompilerType.BOTH && currentBoth || previousCompiler == KotlinJsCompilerType.BOTH && !currentBoth) { - it - } else null - } - } - - val targetNameCandidate = getTargetName(name, compiler) - - return targets.findByName(targetNameCandidate) as KotlinJsTargetDsl? - ?: getPreviousTarget(targetNameCandidate.removeJsCompilerSuffix(KotlinJsCompilerType.LEGACY), true) - ?: getPreviousTarget(lowerCamelCaseName(targetNameCandidate, KotlinJsCompilerType.LEGACY.lowerName), false) -} - -private fun getTargetName(name: String, compiler: KotlinJsCompilerType?): String { - return lowerCamelCaseName( - name, - if (compiler == KotlinJsCompilerType.BOTH) KotlinJsCompilerType.LEGACY.lowerName else null ) } diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/kotlinDomApiDependencyManagement.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/kotlinDomApiDependencyManagement.kt index db44750a470..45db121cecc 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/kotlinDomApiDependencyManagement.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/kotlinDomApiDependencyManagement.kt @@ -16,7 +16,6 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import org.jetbrains.kotlin.gradle.plugin.KotlinTarget import org.jetbrains.kotlin.gradle.plugin.sources.KotlinDependencyScope import org.jetbrains.kotlin.gradle.plugin.sources.sourceSetDependencyConfigurationByScope -import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilation import org.jetbrains.kotlin.gradle.targets.js.npm.SemVer @@ -55,10 +54,6 @@ private fun KotlinTarget.addKotlinDomApiDependency( dependencies: DependencyHandler, coreLibrariesVersion: Provider ) { - if (this is KotlinJsTarget) { - irTarget?.addKotlinDomApiDependency(configurations, dependencies, coreLibrariesVersion) - } - compilations.configureEach { compilation -> if (compilation.platformType != KotlinPlatformType.js) return@configureEach if (compilation !is KotlinJsIrCompilation) return@configureEach diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinTargetConfigurator.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinTargetConfigurator.kt index 4b943d3fabf..28fea0af5a2 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinTargetConfigurator.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinTargetConfigurator.kt @@ -28,7 +28,6 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions import org.jetbrains.kotlin.gradle.plugin.internal.artifactTypeAttribute import org.jetbrains.kotlin.gradle.plugin.mpp.* import org.jetbrains.kotlin.gradle.targets.js.KotlinJsCompilerAttribute -import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget import org.jetbrains.kotlin.gradle.targets.js.KotlinWasmTargetAttribute import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget import org.jetbrains.kotlin.gradle.targets.js.toAttribute @@ -431,10 +430,6 @@ fun Configuration.usesPlatformOf(target: KotlinTarget): Configuration { val publishJsCompilerAttribute = PropertiesProvider(target.project).publishJsCompilerAttribute - if (publishJsCompilerAttribute && target is KotlinJsTarget) { - attributes.attribute(KotlinJsCompilerAttribute.jsCompilerAttribute, KotlinJsCompilerAttribute.legacy) - } - if (publishJsCompilerAttribute && target is KotlinJsIrTarget) { if (target.platformType == KotlinPlatformType.js) { attributes.attribute(KotlinJsCompilerAttribute.jsCompilerAttribute, KotlinJsCompilerAttribute.ir) diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/PropertiesProvider.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/PropertiesProvider.kt index 0684bf44a0b..15c7c90615d 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/PropertiesProvider.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/PropertiesProvider.kt @@ -230,9 +230,6 @@ internal class PropertiesProvider private constructor(private val project: Proje val wasmStabilityNoWarn: Boolean get() = booleanProperty("kotlin.wasm.stability.nowarn") ?: false - val jsCompilerNoWarn: Boolean - get() = booleanProperty("$jsCompilerProperty.nowarn") ?: false - val ignoreDisabledNativeTargets: Boolean? get() = booleanProperty(KOTLIN_NATIVE_IGNORE_DISABLED_TARGETS) @@ -429,27 +426,12 @@ internal class PropertiesProvider private constructor(private val project: Proje val errorJsGenerateExternals: Boolean? get() = booleanProperty("kotlin.js.generate.externals") - /** - * Use Kotlin/JS backend compiler type - */ - val jsCompiler: KotlinJsCompilerType? - get() = this.property(jsCompilerProperty).orNull?.let { KotlinJsCompilerType.byArgumentOrNull(it) } - /** * Use Kotlin/JS backend compiler publishing attribute */ val publishJsCompilerAttribute: Boolean get() = this.booleanProperty("$jsCompilerProperty.publish.attribute") ?: true - /** - * Use Kotlin/JS backend compiler type - */ - val jsGenerateExecutableDefault: Boolean - get() = (booleanProperty("kotlin.js.generate.executable.default") ?: true).also { - KotlinBuildStatsService.getInstance() - ?.report(StringMetrics.JS_GENERATE_EXECUTABLE_DEFAULT, it.toString()) - } - val stdlibDefaultDependency: Boolean get() = booleanProperty(KOTLIN_STDLIB_DEFAULT_DEPENDENCY) ?: true diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/KotlinMultiplatformPlugin.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/KotlinMultiplatformPlugin.kt index de33a4d6a9e..4fecf7a418f 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/KotlinMultiplatformPlugin.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/KotlinMultiplatformPlugin.kt @@ -133,16 +133,9 @@ class KotlinMultiplatformPlugin : Plugin { } fun setupDefaultPresets(project: Project) { - @Suppress("DEPRECATION") with(project.multiplatformExtension.presets) { add(KotlinJvmTargetPreset(project)) - add(KotlinJsTargetPreset(project).apply { irPreset = null }) - add(KotlinJsIrTargetPreset(project).apply { mixedMode = false }) - add( - KotlinJsTargetPreset(project).apply { - irPreset = KotlinJsIrTargetPreset(project).apply { mixedMode = true } - } - ) + add(KotlinJsIrTargetPreset(project)) add(KotlinWasmTargetPreset(project, KotlinWasmTargetType.JS)) add(KotlinWasmTargetPreset(project, KotlinWasmTargetType.WASI)) add(project.objects.newInstance(KotlinAndroidTargetPreset::class.java, project)) diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/compilationImpl/factory/KotlinCompilationDependencyConfigurationsFactories.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/compilationImpl/factory/KotlinCompilationDependencyConfigurationsFactories.kt index 32b42a01d29..6400d62150e 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/compilationImpl/factory/KotlinCompilationDependencyConfigurationsFactories.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/compilationImpl/factory/KotlinCompilationDependencyConfigurationsFactories.kt @@ -14,7 +14,6 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.DefaultKotlinCompi import org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.KotlinCompilationConfigurationsContainer import org.jetbrains.kotlin.gradle.plugin.mpp.javaSourceSets import org.jetbrains.kotlin.gradle.plugin.sources.METADATA_CONFIGURATION_NAME_SUFFIX -import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget import org.jetbrains.kotlin.gradle.utils.* @@ -50,20 +49,6 @@ internal object NativeKotlinCompilationDependencyConfigurationsFactory : } } -internal object JsKotlinCompilationDependencyConfigurationsFactory : - KotlinCompilationImplFactory.KotlinCompilationDependencyConfigurationsFactory { - - override fun create(target: KotlinTarget, compilationName: String): KotlinCompilationConfigurationsContainer { - val defaultNaming = ConfigurationNaming.Default(target, compilationName) - return KotlinCompilationDependencyConfigurationsContainer( - target, compilationName, withRuntime = true, - naming = ConfigurationNaming.Js(target, compilationName), - compileClasspathConfigurationName = defaultNaming.name(compileClasspath), - runtimeClasspathConfigurationName = defaultNaming.name(runtimeClasspath) - ) - } -} - internal class JvmWithJavaCompilationDependencyConfigurationsFactory(private val target: KotlinWithJavaTarget<*, *>) : KotlinCompilationImplFactory.KotlinCompilationDependencyConfigurationsFactory { override fun create(target: KotlinTarget, compilationName: String): KotlinCompilationConfigurationsContainer { @@ -91,22 +76,6 @@ private fun interface ConfigurationNaming { target.disambiguationClassifier, compilationName.takeIf { it != KotlinCompilation.MAIN_COMPILATION_NAME }, *parts ) } - - class Js( - private val target: KotlinTarget, - private val compilationName: String - ) : ConfigurationNaming { - override fun name(vararg parts: String): String = lowerCamelCaseName( - target.disambiguationClassifierInPlatform, compilationName.takeIf { it != KotlinCompilation.MAIN_COMPILATION_NAME }, *parts - ) - - private val KotlinTarget.disambiguationClassifierInPlatform: String? - get() = when (this) { - is KotlinJsTarget -> disambiguationClassifierInPlatform - is KotlinJsIrTarget -> disambiguationClassifierInPlatform - else -> error("Unexpected target type of $this") - } - } } private const val compilation = "compilation" diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/compilationImpl/factory/KotlinCompilationSourceSetsContainerFactories.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/compilationImpl/factory/KotlinCompilationSourceSetsContainerFactories.kt index 50be528080f..c39e3b49699 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/compilationImpl/factory/KotlinCompilationSourceSetsContainerFactories.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/compilationImpl/factory/KotlinCompilationSourceSetsContainerFactories.kt @@ -14,8 +14,6 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataTarget import org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.KotlinCompilationSourceSetsContainer import org.jetbrains.kotlin.gradle.plugin.sources.android.kotlinAndroidSourceSetLayout -import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget -import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName internal class DefaultKotlinCompilationSourceSetsContainerFactory( @@ -50,28 +48,4 @@ internal class AndroidCompilationSourceSetsContainerFactory( ?: lowerCamelCaseName(target.disambiguationClassifier, compilationName) return KotlinCompilationSourceSetsContainer(target.project.kotlinExtension.sourceSets.maybeCreate(sourceSetName)) } -} - -internal object JsCompilationSourceSetsContainerFactory : KotlinCompilationImplFactory.KotlinCompilationSourceSetsContainerFactory { - override fun create(target: KotlinTarget, compilationName: String): KotlinCompilationSourceSetsContainer { - val defaultSourceSetName = lowerCamelCaseName( - if (target is KotlinJsTarget && target.irTarget != null) target.disambiguationClassifierInPlatform - else target.disambiguationClassifier, - compilationName - ) - - return KotlinCompilationSourceSetsContainer(target.project.kotlinExtension.sourceSets.maybeCreate(defaultSourceSetName)) - } -} - -internal object JsIrCompilationSourceSetsContainerFactory : KotlinCompilationImplFactory.KotlinCompilationSourceSetsContainerFactory { - override fun create(target: KotlinTarget, compilationName: String): KotlinCompilationSourceSetsContainer { - val defaultSourceSetName = lowerCamelCaseName( - if (target is KotlinJsIrTarget && target.mixedMode) target.disambiguationClassifierInPlatform - else target.disambiguationClassifier, - compilationName - ) - - return KotlinCompilationSourceSetsContainer(target.project.kotlinExtension.sourceSets.maybeCreate(defaultSourceSetName)) - } -} +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/sources/KotlinSourceSetFactory.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/sources/KotlinSourceSetFactory.kt index e48a1169483..a3cbf2d273b 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/sources/KotlinSourceSetFactory.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/sources/KotlinSourceSetFactory.kt @@ -7,19 +7,12 @@ package org.jetbrains.kotlin.gradle.plugin.sources import org.gradle.api.NamedDomainObjectFactory import org.gradle.api.Project -import org.gradle.api.artifacts.Configuration import org.gradle.api.attributes.Category import org.gradle.api.attributes.Usage -import org.jetbrains.kotlin.gradle.dsl.kotlinExtension import org.jetbrains.kotlin.gradle.plugin.* -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinUsages -import org.jetbrains.kotlin.gradle.targets.js.KotlinJsCompilerAttribute -import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget -import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget import org.jetbrains.kotlin.gradle.targets.metadata.isKotlinGranularMetadataEnabled import org.jetbrains.kotlin.gradle.utils.getOrCreate -import org.jetbrains.kotlin.gradle.utils.targets import java.io.File internal abstract class KotlinSourceSetFactory internal constructor( @@ -108,67 +101,10 @@ internal class DefaultKotlinSourceSetFactory( if (project.isKotlinGranularMetadataEnabled) { attributes.attribute(Usage.USAGE_ATTRIBUTE, project.usageByName(KotlinUsages.KOTLIN_METADATA)) } - - project.afterEvaluate { - setJsCompilerIfNecessary(sourceSet, this) - } } } } - // KT-47163 - // It is necessary to set jsCompilerAttribute to configurations which associated with ONLY js source sets - // Otherwise configuration cannot be resolved because ambiguity between IR and Legacy variants inside one module - private val notOnlyJsSourceSets = mutableSetOf() - - private val jsOnlySourceSetsAttributes = mutableMapOf() - - private fun setJsCompilerIfNecessary(sourceSet: KotlinSourceSet, configuration: Configuration) { - if (sourceSet in notOnlyJsSourceSets) return - - if (sourceSet in jsOnlySourceSetsAttributes) { - configuration.attributes.attribute( - KotlinJsCompilerAttribute.jsCompilerAttribute, - jsOnlySourceSetsAttributes.getValue(sourceSet) - ) - return - } - - project.kotlinExtension.targets - .filter { it !is KotlinJsIrTarget && it !is KotlinJsTarget } - .forEach { target -> - target.compilations.forEach { compilation -> - notOnlyJsSourceSets.addAll(compilation.allKotlinSourceSets) - } - } - - if (sourceSet in notOnlyJsSourceSets) return - - fun chooseCompilerAttribute(target: KotlinTarget): KotlinJsCompilerAttribute { - if (target is KotlinJsIrTarget) { - return KotlinJsCompilerAttribute.ir - } - - target as KotlinJsTarget - return if (target.irTarget != null) KotlinJsCompilerAttribute.ir else KotlinJsCompilerAttribute.legacy - } - - project.kotlinExtension.targets - .filter { it is KotlinJsTarget || (it is KotlinJsIrTarget && it.platformType == KotlinPlatformType.js) } - .forEach { target -> - target.compilations - .filterIsInstance() - .forEach { compilation -> - if (sourceSet in compilation.allKotlinSourceSets) { - val compilerAttribute = chooseCompilerAttribute(target) - jsOnlySourceSetsAttributes[sourceSet] = compilerAttribute - configuration.attributes.attribute(KotlinJsCompilerAttribute.jsCompilerAttribute, compilerAttribute) - return - } - } - } - } - override fun doCreateSourceSet(name: String): DefaultKotlinSourceSet = project.objects.newInstance(DefaultKotlinSourceSet::class.java, project, name) } diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/KotlinJsCompilationFactory.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/KotlinJsCompilationFactory.kt index 61aac6fff82..8974cb1ca11 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/KotlinJsCompilationFactory.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/KotlinJsCompilationFactory.kt @@ -6,24 +6,7 @@ @file:Suppress("PackageDirectoryMismatch") // Old package for compatibility package org.jetbrains.kotlin.gradle.plugin.mpp -import org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.factory.JsCompilationSourceSetsContainerFactory -import org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.factory.JsKotlinCompilationDependencyConfigurationsFactory -import org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.factory.KotlinCompilationImplFactory -import org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.factory.KotlinJsCompilerOptionsFactory +import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilationFactory -class KotlinJsCompilationFactory internal constructor( - override val target: KotlinOnlyTarget -) : KotlinCompilationFactory { - override val itemClass: Class - get() = KotlinJsCompilation::class.java - - private val compilationImplFactory: KotlinCompilationImplFactory = KotlinCompilationImplFactory( - compilerOptionsFactory = KotlinJsCompilerOptionsFactory, - compilationSourceSetsContainerFactory = JsCompilationSourceSetsContainerFactory, - compilationDependencyConfigurationsFactory = JsKotlinCompilationDependencyConfigurationsFactory - ) - - override fun create(name: String): KotlinJsCompilation = target.project.objects.newInstance( - itemClass, compilationImplFactory.create(target, name) - ) -} +@Deprecated("The Kotlin/JS legacy target is deprecated and its support completely discontinued") +typealias KotlinJsCompilationFactory = KotlinJsIrCompilationFactory \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/KotlinJsPlugin.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/KotlinJsPlugin.kt index 8e3bb5e1003..cac3c7cbf41 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/KotlinJsPlugin.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/KotlinJsPlugin.kt @@ -13,7 +13,6 @@ import org.jetbrains.kotlin.gradle.dsl.kotlinExtension import org.jetbrains.kotlin.gradle.internal.customizeKotlinDependencies 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.KotlinJsSingleTargetPreset import org.jetbrains.kotlin.gradle.plugin.mpp.compilerOptions import org.jetbrains.kotlin.gradle.plugin.mpp.internal import org.jetbrains.kotlin.gradle.plugin.mpp.setupGeneralKotlinExtensionParameters @@ -39,7 +38,6 @@ open class KotlinJsPlugin: Plugin { kotlinExtension.apply { irPreset = KotlinJsIrSingleTargetPreset(project) - legacyPreset = KotlinJsSingleTargetPreset(project) } project.runProjectConfigurationHealthCheckWhenEvaluated { diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/KotlinJsTarget.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/KotlinJsTarget.kt index 80727402a9f..2c77a6c1b36 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/KotlinJsTarget.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/KotlinJsTarget.kt @@ -5,252 +5,11 @@ package org.jetbrains.kotlin.gradle.targets.js -import org.gradle.api.NamedDomainObjectContainer -import org.gradle.api.Project -import org.gradle.api.Task -import org.gradle.api.tasks.TaskProvider -import org.jetbrains.kotlin.gradle.dsl.* -import org.jetbrains.kotlin.gradle.plugin.* -import org.jetbrains.kotlin.gradle.plugin.AbstractKotlinTargetConfigurator.Companion.runTaskNameSuffix -import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.MAIN_COMPILATION_NAME -import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType.LEGACY -import org.jetbrains.kotlin.gradle.plugin.mpp.* -import org.jetbrains.kotlin.gradle.plugin.mpp.PRIMARY_SINGLE_COMPONENT_NAME -import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBrowserDsl -import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsNodeDsl -import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsSubTargetContainerDsl -import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl -import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsBinaryContainer -import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget -import org.jetbrains.kotlin.gradle.targets.js.npm.NpmResolverPlugin -import org.jetbrains.kotlin.gradle.targets.js.subtargets.KotlinBrowserJs -import org.jetbrains.kotlin.gradle.targets.js.subtargets.KotlinNodeJs -import org.jetbrains.kotlin.gradle.tasks.locateOrRegisterTask -import org.jetbrains.kotlin.gradle.tasks.locateTask -import org.jetbrains.kotlin.gradle.testing.internal.KotlinTestReport -import org.jetbrains.kotlin.gradle.testing.testTaskName -import org.jetbrains.kotlin.gradle.utils.dashSeparatedName -import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName -import org.jetbrains.kotlin.gradle.utils.newInstance -import org.jetbrains.kotlin.gradle.utils.setProperty -import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly -import org.jetbrains.kotlin.utils.addIfNotNull -import javax.inject.Inject +import org.jetbrains.kotlin.gradle.plugin.KotlinTarget +import org.jetbrains.kotlin.gradle.plugin.mpp.InternalKotlinTarget -abstract class KotlinJsTarget -@Inject -constructor( - project: Project, - platformType: KotlinPlatformType -) : - KotlinTargetWithBinaries(project, platformType), - KotlinTargetWithTests, - KotlinJsTargetDsl, - KotlinJsSubTargetContainerDsl { - override lateinit var testRuns: NamedDomainObjectContainer - internal set - - override var moduleName: String? = null - set(value) { - check(!isBrowserConfigured && !isNodejsConfigured) { - "Please set moduleName before initialize browser() or nodejs()" - } - field = value - } - - internal val commonFakeApiElementsConfigurationName: String - get() = lowerCamelCaseName( - irTarget?.let { - this.disambiguationClassifierInPlatform - } ?: disambiguationClassifier, - "commonFakeApiElements" - ) - - val disambiguationClassifierInPlatform: String? - get() = if (irTarget != null) { - disambiguationClassifier?.removeJsCompilerSuffix(LEGACY) - } else { - disambiguationClassifier - } - - override val kotlinComponents: Set by lazy { - if (irTarget == null) - super.kotlinComponents - else { - val mainCompilation = compilations.getByName(MAIN_COMPILATION_NAME) - val usageContexts = createUsageContexts(mainCompilation).toMutableSet() - - usageContexts += irTarget!!.createUsageContexts(irTarget!!.compilations.getByName(MAIN_COMPILATION_NAME)) - - val componentName = - if (project.kotlinExtension is KotlinMultiplatformExtension) - irTarget?.let { targetName.removeJsCompilerSuffix(LEGACY) } ?: targetName - else PRIMARY_SINGLE_COMPONENT_NAME - - usageContexts.addIfNotNull( - createSourcesJarAndUsageContextIfPublishable( - mainCompilation, - componentName, - dashSeparatedName(targetName.toLowerCaseAsciiOnly()), - mavenScope = KotlinUsageContext.MavenScope.RUNTIME - ) - ) - - val result = createKotlinVariant(componentName, mainCompilation, usageContexts) - - setOf(result) - } - } - - override fun createUsageContexts(producingCompilation: KotlinCompilation<*>): Set { - val usageContexts = super.createUsageContexts(producingCompilation) - - if (isMpp!!) return usageContexts - - return usageContexts + - DefaultKotlinUsageContext( - compilation = compilations.getByName(MAIN_COMPILATION_NAME), - mavenScope = KotlinUsageContext.MavenScope.COMPILE, - dependencyConfigurationName = commonFakeApiElementsConfigurationName, - overrideConfigurationArtifacts = project.setProperty { emptyList() } - ) - } - - override fun createKotlinVariant( - componentName: String, - compilation: KotlinCompilation<*>, - usageContexts: Set - ): KotlinVariant { - return super.createKotlinVariant(componentName, compilation, usageContexts).apply { - irTarget?.let { - artifactTargetName = targetName.removeJsCompilerSuffix(LEGACY) - } - } - } - - override val binaries: KotlinJsBinaryContainer - get() = compilations.withType(KotlinJsCompilation::class.java) - .named(MAIN_COMPILATION_NAME) - .map { it.binaries } - .get() - - var irTarget: KotlinJsIrTarget? = null - internal set - - open var isMpp: Boolean? = null - internal set - - val testTaskName get() = testRuns.getByName(KotlinTargetWithTests.DEFAULT_TEST_RUN_NAME).testTaskName - val testTask: TaskProvider - get() = checkNotNull(project.locateTask(testTaskName)) - - val runTaskName get() = lowerCamelCaseName(disambiguationClassifier, runTaskNameSuffix) - val runTask: TaskProvider - get() = project.locateOrRegisterTask(runTaskName) { - it.description = "Run js on all configured platforms" - } - - private val propertiesProvider = PropertiesProvider(project) - - private val commonLazy by lazy { - NpmResolverPlugin.apply(project) - } - - //Browser - private val browserLazyDelegate = lazy { - commonLazy - project.objects.newInstance(KotlinBrowserJs::class.java, this).also { - it.configure() - - if (propertiesProvider.jsGenerateExecutableDefault && irTarget == null) { - binaries.executable() - } - - browserConfiguredHandlers.forEach { handler -> - handler(it) - } - browserConfiguredHandlers.clear() - } - } - - private val browserConfiguredHandlers = mutableListOf Unit>() - - override val browser by browserLazyDelegate - - override val isBrowserConfigured: Boolean - get() = browserLazyDelegate.isInitialized() - - override fun browser(body: KotlinJsBrowserDsl.() -> Unit) { - body(browser) - irTarget?.browser(body) - } - - //node.js - private val nodejsLazyDelegate = lazy { - commonLazy - project.objects.newInstance(KotlinNodeJs::class.java, this).also { - it.configure() - - if (propertiesProvider.jsGenerateExecutableDefault && irTarget == null) { - binaries.executable() - } - - nodejsConfiguredHandlers.forEach { handler -> - handler(it) - } - - nodejsConfiguredHandlers.clear() - } - } - - private val nodejsConfiguredHandlers = mutableListOf Unit>() - - override val nodejs by nodejsLazyDelegate - - override val isNodejsConfigured: Boolean - get() = nodejsLazyDelegate.isInitialized() - - override fun nodejs(body: KotlinJsNodeDsl.() -> Unit) { - body(nodejs) - irTarget?.nodejs(body) - } - - override fun whenBrowserConfigured(body: KotlinJsBrowserDsl.() -> Unit) { - if (browserLazyDelegate.isInitialized()) { - browser(body) - } else { - browserConfiguredHandlers += body - } - } - - override fun whenNodejsConfigured(body: KotlinJsNodeDsl.() -> Unit) { - if (nodejsLazyDelegate.isInitialized()) { - nodejs(body) - } else { - nodejsConfiguredHandlers += body - } - } - - override fun useCommonJs() { - compilations.all { - it.kotlinOptions { - moduleKind = "commonjs" - sourceMap = true - sourceMapEmbedSources = null - } - } - irTarget?.useCommonJs() - } - - override fun useEsModules() { - error("ES modules are not supported in legacy JS compiler. Please, use IR one instead.") - } - - override fun generateTypeScriptDefinitions() { - project.logger.warn("Legacy compiler does not support generation of TypeScript Definitions") - } - - override val compilerOptions: KotlinJsCompilerOptions = - project.objects - .newInstance() +@Deprecated("The Kotlin/JS legacy target is deprecated and its support completely discontinued", level = DeprecationLevel.WARNING) +abstract class KotlinJsTarget : KotlinTarget, InternalKotlinTarget { + @Deprecated("Only for compatibility") + val irTarget = null } \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/KotlinJsTargetConfigurator.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/KotlinJsTargetConfigurator.kt index cc7e64bbde4..941eb52b8bd 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/KotlinJsTargetConfigurator.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/KotlinJsTargetConfigurator.kt @@ -5,123 +5,7 @@ package org.jetbrains.kotlin.gradle.targets.js -import org.gradle.api.DefaultTask -import org.gradle.api.Task -import org.gradle.api.attributes.Usage -import org.gradle.language.base.plugins.LifecycleBasePlugin -import org.jetbrains.kotlin.gradle.plugin.* -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinUsages -import org.jetbrains.kotlin.gradle.plugin.mpp.addSourceSet -import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider -import org.jetbrains.kotlin.gradle.tasks.locateTask -import org.jetbrains.kotlin.gradle.tasks.registerTask -import org.jetbrains.kotlin.gradle.testing.internal.kotlinTestRegistry -import org.jetbrains.kotlin.gradle.testing.testTaskName -import java.util.concurrent.Callable +import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTargetConfigurator -open class KotlinJsTargetConfigurator : - KotlinOnlyTargetConfigurator(true), - KotlinTargetWithTestsConfigurator { - - override val testRunClass: Class get() = KotlinJsReportAggregatingTestRun::class.java - - override fun createTestRun( - name: String, - target: KotlinJsTarget - ): KotlinJsReportAggregatingTestRun { - val result = target.project.objects.newInstance( - KotlinJsReportAggregatingTestRun::class.java, - name, - target - ) - - val testTask = target.project.kotlinTestRegistry.getOrCreateAggregatedTestTask( - name = result.testTaskName, - description = "Run JS tests for all platforms" - ) - - // workaround to avoid the infinite recursion in item factories of the target and the subtargets: - target.testRuns.matching { it.name == name }.whenObjectAdded { - it.configureAllExecutions { - // do not do anything with the aggregated test run, but ensure that they are created - } - } - - result.executionTask = testTask - - return result - } - - override fun buildCompilationProcessor(compilation: KotlinJsCompilation): KotlinSourceSetProcessor<*> { - val tasksProvider = KotlinTasksProvider() - return Kotlin2JsSourceSetProcessor(tasksProvider, KotlinCompilationInfo(compilation)) - } - - override fun configureCompilationDefaults(target: KotlinJsTarget) { - val project = target.project - - target.compilations.all { compilation -> - @Suppress("DEPRECATION") - compilation.addSourceSet(compilation.defaultSourceSet) - - configureResourceProcessing( - compilation, - compilation.processResourcesTaskName, - project.files(Callable { compilation.allKotlinSourceSets.map { it.resources } }) - ) - - createLifecycleTaskInternal(compilation) - } - } - - private fun createLifecycleTaskInternal(compilation: KotlinJsCompilation) { - val project = compilation.target.project - - compilation.output.classesDirs.from(project.files().builtBy(compilation.compileAllTaskName)) - - val compileAllTask = project.locateTask(compilation.compileAllTaskName) - if (compileAllTask != null) { - compileAllTask.configure { - it.dependsOn(compilation.compileKotlinTaskName) - it.dependsOn(compilation.processResourcesTaskName) - } - } else { - project.registerTask(compilation.compileAllTaskName) { - it.group = LifecycleBasePlugin.BUILD_GROUP - it.description = "Assembles outputs for compilation '${compilation.name}' of target '${compilation.target.name}'" - it.dependsOn(compilation.compileKotlinTaskName) - it.dependsOn(compilation.processResourcesTaskName) - } - } - } - - override fun configureCompilations(target: KotlinJsTarget) { - super.configureCompilations(target) - - target.compilations.all { - it.kotlinOptions { - moduleKind = "umd" - sourceMap = true - sourceMapEmbedSources = null - } - } - } - - override fun defineConfigurationsForTarget(target: KotlinJsTarget) { - super.defineConfigurationsForTarget(target) - - if (target.isMpp!!) return - - target.project.configurations.maybeCreate( - target.commonFakeApiElementsConfigurationName - ).apply { - description = "Common Fake API elements for main." - isVisible = false - isCanBeResolved = false - isCanBeConsumed = true - attributes.attribute(Usage.USAGE_ATTRIBUTE, KotlinUsages.producerApiUsage(target)) - attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.common) - } - } -} \ No newline at end of file +@Deprecated("The Kotlin/JS legacy target is deprecated and its support completely discontinued") +typealias KotlinJsTargetConfigurator = KotlinJsIrTargetConfigurator \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/KotlinJsTargetPreset.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/KotlinJsTargetPreset.kt index 3e2a7676b32..69bbb62d861 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/KotlinJsTargetPreset.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/KotlinJsTargetPreset.kt @@ -9,102 +9,18 @@ package org.jetbrains.kotlin.gradle.plugin.mpp import org.gradle.api.Project -import org.jetbrains.kotlin.gradle.plugin.* -import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService -import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget -import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTargetConfigurator -import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTargetPreset -import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName -import org.jetbrains.kotlin.gradle.utils.runProjectConfigurationHealthCheckWhenEvaluated -import org.jetbrains.kotlin.statistics.metrics.StringMetrics -import org.jetbrains.kotlin.util.capitalizeDecapitalize.decapitalizeAsciiOnly -open class KotlinJsTargetPreset( +@Deprecated("The Kotlin/JS legacy target is deprecated and its support completely discontinued", level = DeprecationLevel.WARNING) +abstract class KotlinJsTargetPreset( project: Project -) : KotlinOnlyTargetPreset( +) : KotlinOnlyTargetPreset, KotlinJsCompilation>( project -) { - var irPreset: KotlinJsIrTargetPreset? = null - internal set +) - open val isMpp: Boolean - get() = true - - override val platformType: KotlinPlatformType - get() = KotlinPlatformType.js - - override fun useDisambiguationClassifierAsSourceSetNamePrefix() = irPreset == null - - override fun overrideDisambiguationClassifierOnIdeImport(name: String): String? = - irPreset?.let { - name.removeJsCompilerSuffix(KotlinJsCompilerType.LEGACY) - } - - override fun instantiateTarget(name: String): KotlinJsTarget { - return project.objects.newInstance( - KotlinJsTarget::class.java, - project, - platformType - ).apply { - this.irTarget = irPreset?.createTarget( - lowerCamelCaseName( - name.removeJsCompilerSuffix(KotlinJsCompilerType.LEGACY), - KotlinJsCompilerType.IR.lowerName - ) - )?.also { - it.legacyTarget = this - } - this.isMpp = this@KotlinJsTargetPreset.isMpp - - project.runProjectConfigurationHealthCheckWhenEvaluated { - val buildStatsService = KotlinBuildStatsService.getInstance() - when { - isBrowserConfigured && isNodejsConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "both") - isBrowserConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "browser") - isNodejsConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "nodejs") - !isBrowserConfigured && !isNodejsConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "none") - } - Unit - } - } - } - - override fun createKotlinTargetConfigurator() = KotlinJsTargetConfigurator() - - override fun getName(): String { - return lowerCamelCaseName( - PRESET_NAME, - irPreset?.let { KotlinJsCompilerType.BOTH.lowerName } - ) - } - - override fun createCompilationFactory(forTarget: KotlinJsTarget): KotlinJsCompilationFactory { - return KotlinJsCompilationFactory(forTarget) - } - - companion object { - const val PRESET_NAME = "js" - } -} - -class KotlinJsSingleTargetPreset( +@Suppress("DEPRECATION") +@Deprecated("The Kotlin/JS legacy target is deprecated and its support completely discontinued", level = DeprecationLevel.HIDDEN) +abstract class KotlinJsSingleTargetPreset( project: Project ) : KotlinJsTargetPreset( project -) { - override val isMpp: Boolean - get() = false - - override fun overrideDisambiguationClassifierOnIdeImport(name: String): String? = - null - - // In a Kotlin/JS single-platform project, we don't need any disambiguation suffixes or prefixes in the names: - override fun provideTargetDisambiguationClassifier(target: KotlinOnlyTarget): String? = - irPreset?.let { - super.provideTargetDisambiguationClassifier(target) - ?.removePrefix(target.name.removeJsCompilerSuffix(KotlinJsCompilerType.LEGACY)) - ?.decapitalizeAsciiOnly() - } - - override fun createKotlinTargetConfigurator() = KotlinJsTargetConfigurator() -} +) diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/KotlinJsTargets.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/KotlinJsTargets.kt deleted file mode 100644 index d984bd7b9e5..00000000000 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/KotlinJsTargets.kt +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2010-2020 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.targets.js - -import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType -import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl -import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget - -fun KotlinJsTargetDsl.calculateJsCompilerType(): KotlinJsCompilerType { - return when { - this is KotlinJsTarget && this.irTarget == null -> KotlinJsCompilerType.LEGACY - this is KotlinJsIrTarget && !this.mixedMode -> KotlinJsCompilerType.IR - this is KotlinJsTarget && this.irTarget != null -> KotlinJsCompilerType.BOTH - else -> throw IllegalStateException("Unable to find previous Kotlin/JS compiler type for $this") - } -} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsBinaryContainer.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsBinaryContainer.kt index a9a32d0ded2..56d1e7b46a0 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsBinaryContainer.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsBinaryContainer.kt @@ -9,23 +9,15 @@ import org.gradle.api.DomainObjectSet import org.gradle.api.GradleException import org.gradle.api.Project import org.gradle.api.plugins.ExtensionAware -import org.gradle.language.base.plugins.LifecycleBasePlugin import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinTargetWithBinaries import org.jetbrains.kotlin.gradle.plugin.mpp.isMain -import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget -import org.jetbrains.kotlin.gradle.targets.js.KotlinWasmTargetType import org.jetbrains.kotlin.gradle.targets.js.binaryen.BinaryenExec -import org.jetbrains.kotlin.gradle.targets.js.dsl.Distribution import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBinaryMode import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBinaryMode.DEVELOPMENT import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBinaryMode.PRODUCTION -import org.jetbrains.kotlin.gradle.targets.js.subtargets.DefaultDistribution -import org.jetbrains.kotlin.gradle.targets.js.subtargets.KotlinJsSubTarget -import org.jetbrains.kotlin.gradle.targets.js.subtargets.createDefaultDistribution -import org.jetbrains.kotlin.gradle.tasks.dependsOn import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly import javax.inject.Inject @@ -34,7 +26,7 @@ open class KotlinJsBinaryContainer @Inject constructor( val target: KotlinTargetWithBinaries, - backingContainer: DomainObjectSet + backingContainer: DomainObjectSet, ) : DomainObjectSet by backingContainer { val project: Project get() = target.project @@ -47,7 +39,7 @@ constructor( // For Groovy DSL @JvmOverloads fun executable( - compilation: KotlinJsCompilation = defaultCompilation + compilation: KotlinJsCompilation = defaultCompilation, ): List { if (target is KotlinJsIrTarget) { target.whenBrowserConfigured { @@ -65,22 +57,7 @@ constructor( return compilation.binaries.executableIrInternal(compilation) } - if (target is KotlinJsTarget) { - target.irTarget - ?.let { throw IllegalStateException("Can't use `executable()` with 'both' compiler type") } - - target.whenBrowserConfigured { - (this as KotlinJsSubTarget).produceExecutable() - } - - target.whenNodejsConfigured { - (this as KotlinJsSubTarget).produceExecutable() - } - - return compilation.binaries.executableLegacyInternal(compilation) - } - - throw GradleException("Target should be either KotlinJsTarget or KotlinJsIrTarget, but found $target") + throw GradleException("Target should be KotlinJsIrTarget, but found $target") } internal fun executableIrInternal(compilation: KotlinJsCompilation): List = createBinaries( @@ -95,23 +72,10 @@ constructor( } ) - private fun executableLegacyInternal(compilation: KotlinJsCompilation) = createBinaries( - compilation = compilation, - jsBinaryType = KotlinJsBinaryType.EXECUTABLE, - create = { jsCompilation, name, type -> - object : JsBinary { - override val compilation: KotlinJsCompilation = jsCompilation - override val name: String = name - override val mode: KotlinJsBinaryMode = type - override val distribution: Distribution = createDefaultDistribution(jsCompilation.target.project, jsCompilation.target.targetName) - } - } - ) - // For Groovy DSL @JvmOverloads fun library( - compilation: KotlinJsCompilation = defaultCompilation + compilation: KotlinJsCompilation = defaultCompilation, ): List { if (target is KotlinJsIrTarget) { target.whenBrowserConfigured { @@ -142,7 +106,7 @@ constructor( } internal fun getIrBinaries( - mode: KotlinJsBinaryMode + mode: KotlinJsBinaryMode, ): DomainObjectSet = withType(JsIrBinary::class.java) .matching { it.mode == mode } @@ -151,7 +115,7 @@ constructor( compilation: KotlinJsCompilation, modes: Collection = listOf(PRODUCTION, DEVELOPMENT), jsBinaryType: KotlinJsBinaryType, - create: (compilation: KotlinJsCompilation, name: String, mode: KotlinJsBinaryMode) -> T + create: (compilation: KotlinJsCompilation, name: String, mode: KotlinJsBinaryMode) -> T, ) = modes.map { createBinary( @@ -166,7 +130,7 @@ constructor( compilation: KotlinJsCompilation, mode: KotlinJsBinaryMode, jsBinaryType: KotlinJsBinaryType, - create: (compilation: KotlinJsCompilation, name: String, mode: KotlinJsBinaryMode) -> T + create: (compilation: KotlinJsCompilation, name: String, mode: KotlinJsBinaryMode) -> T, ): JsBinary { val name = generateBinaryName( compilation, @@ -194,7 +158,7 @@ constructor( internal fun generateBinaryName( compilation: KotlinJsCompilation, mode: KotlinJsBinaryMode, - jsBinaryType: KotlinJsBinaryType? + jsBinaryType: KotlinJsBinaryType?, ) = lowerCamelCaseName( if (compilation.isMain()) null else compilation.name, diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrCompilationFactory.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrCompilationFactory.kt index c4f64e2d6a9..c5e04e900ff 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrCompilationFactory.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrCompilationFactory.kt @@ -13,8 +13,6 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.factory.* import org.jetbrains.kotlin.gradle.plugin.mpp.isMain import org.jetbrains.kotlin.gradle.plugin.mpp.sourcesJarTask import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly -import org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.factory.JsIrCompilationSourceSetsContainerFactory -import org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.factory.JsKotlinCompilationDependencyConfigurationsFactory import org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.factory.KotlinCompilationImplFactory import org.jetbrains.kotlin.gradle.plugin.mpp.compilationImpl.factory.KotlinJsCompilerOptionsFactory @@ -31,8 +29,6 @@ class KotlinJsIrCompilationFactory internal constructor( target.project.files() } ), - compilationSourceSetsContainerFactory = JsIrCompilationSourceSetsContainerFactory, - compilationDependencyConfigurationsFactory = JsKotlinCompilationDependencyConfigurationsFactory, preConfigureAction = DefaultKotlinCompilationPreConfigure + { compilation -> if (compilation.platformType == KotlinPlatformType.wasm && compilation.isMain()) { val artifactNameAppendix = (compilation.target as KotlinJsIrTarget).wasmDecamelizedDefaultNameOrNull() diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrTarget.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrTarget.kt index 40dc8ed15c7..33717998f0f 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrTarget.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrTarget.kt @@ -11,20 +11,18 @@ import org.gradle.api.Task import org.gradle.api.provider.Provider import org.gradle.api.tasks.TaskProvider import org.gradle.language.base.plugins.LifecycleBasePlugin -import org.jetbrains.kotlin.gradle.dsl.KotlinJsOptions -import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension -import org.jetbrains.kotlin.gradle.dsl.kotlinExtension -import org.jetbrains.kotlin.gradle.plugin.* import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi import org.jetbrains.kotlin.gradle.dsl.* -import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompilerOptionsDefault import org.jetbrains.kotlin.gradle.plugin.AbstractKotlinTargetConfigurator.Companion.runTaskNameSuffix +import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.MAIN_COMPILATION_NAME +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType +import org.jetbrains.kotlin.gradle.plugin.KotlinTargetComponent +import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider import org.jetbrains.kotlin.gradle.plugin.mpp.* import org.jetbrains.kotlin.gradle.targets.js.JsAggregatingExecutionSource import org.jetbrains.kotlin.gradle.targets.js.KotlinJsReportAggregatingTestRun -import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget import org.jetbrains.kotlin.gradle.targets.js.KotlinWasmTargetType import org.jetbrains.kotlin.gradle.targets.js.binaryen.BinaryenExec import org.jetbrains.kotlin.gradle.targets.js.dsl.* @@ -35,11 +33,6 @@ import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject import org.jetbrains.kotlin.gradle.targets.js.typescript.TypeScriptValidationTask import org.jetbrains.kotlin.gradle.tasks.* import org.jetbrains.kotlin.gradle.utils.* -import org.jetbrains.kotlin.gradle.utils.dashSeparatedName -import org.jetbrains.kotlin.gradle.utils.decamelize -import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName -import org.jetbrains.kotlin.gradle.utils.newInstance -import org.jetbrains.kotlin.gradle.utils.setProperty import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeAsciiOnly import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly import org.jetbrains.kotlin.utils.addIfNotNull @@ -51,7 +44,6 @@ abstract class KotlinJsIrTarget constructor( project: Project, platformType: KotlinPlatformType, - internal val mixedMode: Boolean, ) : KotlinTargetWithBinaries(project, platformType), KotlinTargetWithTests, @@ -71,9 +63,6 @@ constructor( override var wasmTargetType: KotlinWasmTargetType? = null internal set - var legacyTarget: KotlinJsTarget? = null - internal set - override var moduleName: String? = null set(value) { check(!isBrowserConfigured && !isNodejsConfigured) { @@ -117,7 +106,7 @@ constructor( override fun createUsageContexts(producingCompilation: KotlinCompilation<*>): Set { val usageContexts = super.createUsageContexts(producingCompilation) - if (isMpp!! || mixedMode) return usageContexts + if (isMpp!!) return usageContexts return usageContexts + DefaultKotlinUsageContext( @@ -130,20 +119,10 @@ constructor( internal val commonFakeApiElementsConfigurationName: String get() = lowerCamelCaseName( - if (mixedMode) - disambiguationClassifierInPlatform - else - disambiguationClassifier, + disambiguationClassifier, "commonFakeApiElements" ) - val disambiguationClassifierInPlatform: String? - get() = if (mixedMode) { - disambiguationClassifier?.removeJsCompilerSuffix(KotlinJsCompilerType.IR) - } else { - disambiguationClassifier - } - override val binaries: KotlinJsBinaryContainer get() = compilations.withType(KotlinJsIrCompilation::class.java) .named(MAIN_COMPILATION_NAME) diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrTargetPreset.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrTargetPreset.kt index 5b5e3ad7173..bfdd703cc41 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrTargetPreset.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinJsIrTargetPreset.kt @@ -7,43 +7,40 @@ package org.jetbrains.kotlin.gradle.targets.js.ir import org.gradle.api.Project import org.jetbrains.kotlin.gradle.DeprecatedTargetPresetApi -import org.jetbrains.kotlin.gradle.plugin.* +import org.jetbrains.kotlin.gradle.plugin.AbstractKotlinTargetConfigurator +import org.jetbrains.kotlin.gradle.plugin.KotlinOnlyTargetConfigurator +import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinCompilationFactory import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinOnlyTarget import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinOnlyTargetPreset import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService -import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName import org.jetbrains.kotlin.gradle.utils.runProjectConfigurationHealthCheckWhenEvaluated import org.jetbrains.kotlin.statistics.metrics.StringMetrics -import org.jetbrains.kotlin.util.capitalizeDecapitalize.decapitalizeAsciiOnly @DeprecatedTargetPresetApi open class KotlinJsIrTargetPreset( - project: Project + project: Project, ) : KotlinOnlyTargetPreset( project ) { - internal var mixedMode: Boolean? = null - open val isMpp: Boolean get() = true override val platformType: KotlinPlatformType = KotlinPlatformType.js override fun instantiateTarget(name: String): KotlinJsIrTarget { - return project.objects.newInstance(KotlinJsIrTarget::class.java, project, platformType, mixedMode).apply { + return project.objects.newInstance(KotlinJsIrTarget::class.java, project, platformType).apply { this.isMpp = this@KotlinJsIrTargetPreset.isMpp - if (!mixedMode) { - project.runProjectConfigurationHealthCheckWhenEvaluated { - val buildStatsService = KotlinBuildStatsService.getInstance() - when { - isBrowserConfigured && isNodejsConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "both") - isBrowserConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "browser") - isNodejsConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "nodejs") - !isBrowserConfigured && !isNodejsConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "none") - } - Unit + project.runProjectConfigurationHealthCheckWhenEvaluated { + + val buildStatsService = KotlinBuildStatsService.getInstance() + when { + isBrowserConfigured && isNodejsConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "both") + isBrowserConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "browser") + isNodejsConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "nodejs") + !isBrowserConfigured && !isNodejsConfigured -> buildStatsService?.report(StringMetrics.JS_TARGET_MODE, "none") } + Unit } } } @@ -55,21 +52,18 @@ open class KotlinJsIrTargetPreset( //TODO[Ilya Goncharov] remove public morozov public override fun createCompilationFactory( - forTarget: KotlinJsIrTarget + forTarget: KotlinJsIrTarget, ): KotlinCompilationFactory = KotlinJsIrCompilationFactory(forTarget) companion object { - val JS_PRESET_NAME = lowerCamelCaseName( - "js", - KotlinJsCompilerType.IR.lowerName - ) + val JS_PRESET_NAME = "js" } } @DeprecatedTargetPresetApi class KotlinJsIrSingleTargetPreset( - project: Project + project: Project, ) : KotlinJsIrTargetPreset( project ) { @@ -78,13 +72,7 @@ class KotlinJsIrSingleTargetPreset( // In a Kotlin/JS single-platform project, we don't need any disambiguation suffixes or prefixes in the names: override fun provideTargetDisambiguationClassifier(target: KotlinOnlyTarget): String? { - return if (mixedMode!!) { - super.provideTargetDisambiguationClassifier(target) - ?.removePrefix(target.name.removeJsCompilerSuffix(KotlinJsCompilerType.IR)) - ?.decapitalizeAsciiOnly() - } else { - null - } + return null } override fun createKotlinTargetConfigurator(): KotlinOnlyTargetConfigurator = diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinWasmTargetPreset.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinWasmTargetPreset.kt index 7294af9329b..4c41724a42a 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinWasmTargetPreset.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/ir/KotlinWasmTargetPreset.kt @@ -26,7 +26,7 @@ class KotlinWasmTargetPreset( project.logger.warn("New 'wasm' target is Work-in-Progress and is subject to change without notice.") } - val irTarget = project.objects.newInstance(KotlinJsIrTarget::class.java, project, KotlinPlatformType.wasm, false) + val irTarget = project.objects.newInstance(KotlinJsIrTarget::class.java, project, KotlinPlatformType.wasm) irTarget.isMpp = true irTarget.wasmTargetType = targetType diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/npm/resolver/KotlinProjectNpmResolver.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/npm/resolver/KotlinProjectNpmResolver.kt index c3d980e76fc..4af636bd6e6 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/npm/resolver/KotlinProjectNpmResolver.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/npm/resolver/KotlinProjectNpmResolver.kt @@ -14,7 +14,6 @@ import org.jetbrains.kotlin.gradle.dsl.kotlinExtensionOrNull import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType import org.jetbrains.kotlin.gradle.plugin.KotlinTarget import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation -import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget import org.jetbrains.kotlin.gradle.targets.js.npm.KotlinNpmResolutionManager import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinProjectNpmResolution import java.io.Serializable @@ -73,15 +72,6 @@ class KotlinProjectNpmResolver( addCompilation(compilation) } } - - // Hack for mixed mode, when target is JS and contain JS-IR - if (target is KotlinJsTarget) { - target.irTarget?.compilations?.all { compilation -> - if (compilation is KotlinJsCompilation) { - addCompilation(compilation) - } - } - } } } diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/subtargets/KotlinBrowserJs.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/subtargets/KotlinBrowserJs.kt index ebce47bee3b..3f3adb6a936 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/subtargets/KotlinBrowserJs.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/subtargets/KotlinBrowserJs.kt @@ -5,381 +5,10 @@ package org.jetbrains.kotlin.gradle.targets.js.subtargets -import org.gradle.api.Action -import org.gradle.api.Task -import org.gradle.api.provider.Property -import org.gradle.api.tasks.Copy -import org.gradle.api.tasks.TaskProvider -import org.gradle.language.base.plugins.LifecycleBasePlugin -import org.jetbrains.kotlin.gradle.dsl.KotlinJsDce -import org.jetbrains.kotlin.gradle.plugin.COMPILER_CLASSPATH_CONFIGURATION_NAME -import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation -import org.jetbrains.kotlin.gradle.plugin.mpp.isMain -import org.jetbrains.kotlin.gradle.plugin.mpp.isTest -import org.jetbrains.kotlin.gradle.utils.archivesName -import org.jetbrains.kotlin.gradle.utils.distsDirectory -import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget -import org.jetbrains.kotlin.gradle.targets.js.dsl.* -import org.jetbrains.kotlin.gradle.targets.js.ir.executeTaskBaseName -import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension -import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin.Companion.kotlinNodeJsExtension -import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject -import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest -import org.jetbrains.kotlin.gradle.targets.js.testing.karma.KotlinKarma -import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack -import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig -import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig.Mode -import org.jetbrains.kotlin.gradle.targets.js.webpack.WebpackDevtool -import org.jetbrains.kotlin.gradle.tasks.dependsOn -import org.jetbrains.kotlin.gradle.tasks.registerTask -import org.jetbrains.kotlin.gradle.utils.doNotTrackStateCompat -import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName -import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly -import java.io.File -import javax.inject.Inject -import org.jetbrains.kotlin.gradle.tasks.KotlinJsDce as KotlinJsDceTask +import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBrowserDsl -abstract class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) : - KotlinJsSubTarget(target, "browser"), - KotlinJsBrowserDsl { - - private val webpackTaskConfigurations: MutableList> = mutableListOf() - private val runTaskConfigurations: MutableList> = mutableListOf() - private val dceConfigurations: MutableList> = mutableListOf() - private val distribution: Distribution = createDefaultDistribution(project, target.targetName) - - override val testTaskDescription: String - get() = "Run all ${target.name} tests inside browser using karma and webpack" - - override fun configureDefaultTestFramework(testTask: KotlinJsTest) { - testTask.useKarma { - useChromeHeadless() - } - } - - override fun commonWebpackConfig(body: Action) { - webpackTaskConfigurations.add { - it.webpackConfigApplier(body) - } - runTaskConfigurations.add { - it.webpackConfigApplier(body) - } - testTask(Action { - it.onTestFrameworkSet { - if (it is KotlinKarma) { - body.execute(it.webpackConfig) - } - } - }) - } - - override fun runTask(body: Action) { - runTaskConfigurations.add(body) - } - - @ExperimentalDistributionDsl - override fun distribution(body: Action) { - body.execute(distribution) - } - - override fun webpackTask(body: Action) { - webpackTaskConfigurations.add(body) - } - - @ExperimentalDceDsl - override fun dceTask(body: Action) { - dceConfigurations.add(body) - } - - override fun configureMain(compilation: KotlinJsCompilation) { - val (dceTaskProvider, devDceTaskProvider) = compilation.configureDceTasks() - - // Adding dce tasks to additional JS compilations - target.compilations.configureEach { - if (!it.isMain() && !it.isTest()) it.configureDceTasks() - } - - configureRun( - compilation = compilation, - dceTaskProvider = dceTaskProvider, - devDceTaskProvider = devDceTaskProvider - ) - configureBuild( - compilation = compilation, - dceTaskProvider = dceTaskProvider, - devDceTaskProvider = devDceTaskProvider - ) - } - - private fun KotlinJsCompilation.configureDceTasks(): Pair, TaskProvider> { - val dceTaskProvider = configureDce( - compilation = this, - dev = false - ) - - val devDceTaskProvider = configureDce( - compilation = this, - dev = true - ) - - return dceTaskProvider to devDceTaskProvider - } - - private fun configureRun( - compilation: KotlinJsCompilation, - dceTaskProvider: TaskProvider, - devDceTaskProvider: TaskProvider - ) { - val project = compilation.target.project - val nodeJs = project.rootProject.kotlinNodeJsExtension - - val commonRunTask = registerSubTargetTask(disambiguateCamelCased(RUN_TASK_NAME)) {} - - compilation.binaries - .all { binary -> - val type = binary.mode - val distsDirectory = project.distsDirectory - val archivesName = project.archivesName - - val runTask = registerSubTargetTask( - disambiguateCamelCased( - binary.executeTaskBaseName, - RUN_TASK_NAME - ), - listOf(compilation) - ) { task -> - task.outputDirectory.convention(distsDirectory).finalizeValueOnRead() - task.args.add(0, "serve") - - task.description = "start ${type.name.toLowerCaseAsciiOnly()} webpack dev server" - - task.devServer = KotlinWebpackConfig.DevServer( - open = true, - static = mutableListOf(compilation.output.resourcesDir.canonicalPath), - client = KotlinWebpackConfig.DevServer.Client( - KotlinWebpackConfig.DevServer.Client.Overlay( - errors = true, - warnings = false - ) - ) - ) - - task.doNotTrackStateCompat("Tracked by external webpack tool") - - task.commonConfigure( - compilation = compilation, - dceTaskProvider = dceTaskProvider, - devDceTaskProvider = devDceTaskProvider, - mode = type, - configurationActions = runTaskConfigurations, - nodeJs = nodeJs, - defaultArchivesName = archivesName, - ) - } - - if (type == KotlinJsBinaryMode.DEVELOPMENT) { - target.runTask.dependsOn(runTask) - commonRunTask.configure { - it.dependsOn(runTask) - } - } - } - } - - private fun configureBuild( - compilation: KotlinJsCompilation, - dceTaskProvider: TaskProvider, - devDceTaskProvider: TaskProvider - ) { - val project = compilation.target.project - val nodeJs = project.rootProject.kotlinNodeJsExtension - - val processResourcesTask = target.project.tasks.named(compilation.processResourcesTaskName) - - val distributeResourcesTask = registerSubTargetTask( - disambiguateCamelCased( - DISTRIBUTE_RESOURCES_TASK_NAME - ) - ) { - it.from(processResourcesTask) - it.into(distribution.directory) - } - - val assembleTaskProvider = project.tasks.named(LifecycleBasePlugin.ASSEMBLE_TASK_NAME) - assembleTaskProvider.dependsOn(distributeResourcesTask) - - compilation.binaries - .all { binary -> - val type = binary.mode - val archivesName = project.archivesName - - val webpackTask = registerSubTargetTask( - disambiguateCamelCased( - binary.executeTaskBaseName, - WEBPACK_TASK_NAME - - ), - listOf(compilation) - ) { task -> - task.dependsOn( - distributeResourcesTask - ) - - task.description = "build webpack ${type.name.toLowerCaseAsciiOnly()} bundle" - task.outputDirectory.fileValue(distribution.directory).finalizeValueOnRead() - - task.commonConfigure( - compilation = compilation, - dceTaskProvider = dceTaskProvider, - devDceTaskProvider = devDceTaskProvider, - mode = type, - configurationActions = webpackTaskConfigurations, - nodeJs = nodeJs, - defaultArchivesName = archivesName, - ) - } - - if (type == KotlinJsBinaryMode.PRODUCTION) { - assembleTaskProvider.dependsOn(webpackTask) - val webpackCommonTask = registerSubTargetTask( - disambiguateCamelCased(WEBPACK_TASK_NAME) - ) { - it.dependsOn(webpackTask) - } - registerSubTargetTask(disambiguateCamelCased(DISTRIBUTION_TASK_NAME)) { - it.dependsOn(webpackCommonTask) - it.dependsOn(distributeResourcesTask) - - it.outputs.dir(distribution.directory) - } - } - } - } - - private fun KotlinWebpack.commonConfigure( - compilation: KotlinJsCompilation, - dceTaskProvider: TaskProvider, - devDceTaskProvider: TaskProvider, - mode: KotlinJsBinaryMode, - configurationActions: List>, - nodeJs: NodeJsRootExtension, - defaultArchivesName: Property, - ) { - dependsOn( - nodeJs.npmInstallTaskProvider, - nodeJs.storeYarnLockTaskProvider, - target.project.tasks.named(compilation.processResourcesTaskName) - ) - - configureOptimization(mode) - - val actualDceTaskProvider = when (mode) { - KotlinJsBinaryMode.PRODUCTION -> dceTaskProvider - KotlinJsBinaryMode.DEVELOPMENT -> devDceTaskProvider - } - - dependsOn(actualDceTaskProvider) - - inputFilesDirectory.set( - actualDceTaskProvider.flatMap { dceTask -> - compilation.compileTaskProvider.flatMap { compileTask -> - dceTask.destinationDirectory - } - } - ) - - entryModuleName.set( - compilation.compileTaskProvider.flatMap { compileTask -> - compileTask.outputFileProperty.map { it.nameWithoutExtension } - } - ) - - this.esModules.convention(false).finalizeValueOnRead() - - resolveFromModulesFirst = true - - mainOutputFileName.convention(defaultArchivesName.orElse("main").map { "$it.js" }).finalizeValueOnRead() - - configurationActions.forEach { configure -> - configure.execute(this) - } - } - - private fun configureDce( - compilation: KotlinJsCompilation, - dev: Boolean - ): TaskProvider { - val project = compilation.target.project - - val dceTaskName = lowerCamelCaseName( - DCE_TASK_PREFIX, - if (dev) DCE_DEV_PART else null, - compilation.target.disambiguationClassifier, - compilation.name.takeIf { it != KotlinCompilation.MAIN_COMPILATION_NAME }, - DCE_TASK_SUFFIX - ) - - val kotlinTask = compilation.compileKotlinTaskProvider - - return project.registerTask(dceTaskName) { - if (dev) { - it.dceOptions.devMode = true - } else { - dceConfigurations.forEach { configure -> - configure.execute(it) - } - } - - it.kotlinFilesOnly = true - - it.libraries.from(project.configurations.getByName(compilation.runtimeDependencyConfigurationName)) - it.destinationDirectory.set( - it.dceOptions.outputDirectory?.let { File(it) } - ?: compilation.npmProject.dir.resolve(if (dev) DCE_DEV_DIR else DCE_DIR) - ) - it.defaultCompilerClasspath.setFrom(project.configurations.named(COMPILER_CLASSPATH_CONFIGURATION_NAME)) - it.runViaBuildToolsApi.value(false).disallowChanges() // The legacy backend task is not going to be supported - it.setSource(kotlinTask.map { it.outputFileProperty }) - } - } - - private fun KotlinWebpack.configureOptimization(kind: KotlinJsBinaryMode) { - mode = getByKind( - kind = kind, - releaseValue = Mode.PRODUCTION, - debugValue = Mode.DEVELOPMENT - ) - - devtool = getByKind( - kind = kind, - releaseValue = WebpackDevtool.SOURCE_MAP, - debugValue = WebpackDevtool.EVAL_SOURCE_MAP - ) - } - - private fun getByKind( - kind: KotlinJsBinaryMode, - releaseValue: T, - debugValue: T - ): T = when (kind) { - KotlinJsBinaryMode.PRODUCTION -> releaseValue - KotlinJsBinaryMode.DEVELOPMENT -> debugValue - } - - companion object { - const val DCE_TASK_PREFIX = "processDce" - private const val DCE_DEV_PART = "dev" - const val DCE_TASK_SUFFIX = "kotlinJs" - - const val DCE_DIR = "kotlin-dce" - const val DCE_DEV_DIR = "kotlin-dce-dev" - - const val PRODUCTION = "production" - const val DEVELOPMENT = "development" - - private const val WEBPACK_TASK_NAME = "webpack" - private const val DISTRIBUTE_RESOURCES_TASK_NAME = "distributeResources" - private const val DISTRIBUTION_TASK_NAME = "distribution" - } -} \ No newline at end of file +@Suppress("DEPRECATION") +@Deprecated("The Kotlin/JS legacy target is deprecated and its support completely discontinued", level = DeprecationLevel.HIDDEN) +abstract class KotlinBrowserJs : + KotlinJsSubTarget(), + KotlinJsBrowserDsl \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/subtargets/KotlinJsSubTarget.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/subtargets/KotlinJsSubTarget.kt index dd0e2441e4b..5caf1b372de 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/subtargets/KotlinJsSubTarget.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/subtargets/KotlinJsSubTarget.kt @@ -5,169 +5,7 @@ package org.jetbrains.kotlin.gradle.targets.js.subtargets -import org.gradle.api.Action -import org.gradle.api.NamedDomainObjectContainer -import org.gradle.api.Task -import org.gradle.api.plugins.ExtensionAware -import org.gradle.api.tasks.TaskProvider -import org.gradle.language.base.plugins.LifecycleBasePlugin -import org.jetbrains.kotlin.gradle.plugin.AbstractKotlinTargetConfigurator -import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation -import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation -import org.jetbrains.kotlin.gradle.plugin.mpp.isMain -import org.jetbrains.kotlin.gradle.plugin.whenEvaluated -import org.jetbrains.kotlin.gradle.targets.js.KotlinJsPlatformTestRun -import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsSubTargetDsl -import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin.Companion.kotlinNodeJsExtension -import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject -import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest -import org.jetbrains.kotlin.gradle.tasks.registerTask -import org.jetbrains.kotlin.gradle.testing.internal.configureConventions -import org.jetbrains.kotlin.gradle.testing.internal.kotlinTestRegistry -import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName -abstract class KotlinJsSubTarget( - val target: KotlinJsTarget, - private val disambiguationClassifier: String -) : KotlinJsSubTargetDsl { - val project get() = target.project - - private val nodeJs = project.rootProject.kotlinNodeJsExtension - private val nodeJsTaskProviders = project.rootProject.kotlinNodeJsExtension - - abstract val testTaskDescription: String - - final override lateinit var testRuns: NamedDomainObjectContainer - private set - - protected val taskGroupName = "Kotlin $disambiguationClassifier" - - private val produceExecutable: Unit by lazy { - configureMain() - } - - internal fun produceExecutable() { - produceExecutable - } - - internal fun configure() { - configureTests() - - target.compilations.all { - val npmProject = it.npmProject - it.kotlinOptions { - outputFile = npmProject.dir.resolve(npmProject.main).canonicalPath - } - } - } - - override fun testTask(body: Action) { - testRuns.getByName(KotlinTargetWithTests.DEFAULT_TEST_RUN_NAME).executionTask.configure(body) - } - - protected fun disambiguateCamelCased(vararg names: String): String = - lowerCamelCaseName(target.disambiguationClassifier, disambiguationClassifier, *names) - - private fun configureTests() { - testRuns = project.container(KotlinJsPlatformTestRun::class.java) { name -> KotlinJsPlatformTestRun(name, target) }.also { - (this as ExtensionAware).extensions.add(this::testRuns.name, it) - } - - testRuns.all { configureTestRunDefaults(it) } - testRuns.create(KotlinTargetWithTests.DEFAULT_TEST_RUN_NAME) - } - - protected open fun configureTestRunDefaults(testRun: KotlinJsPlatformTestRun) { - target.compilations.matching { it.name == KotlinCompilation.TEST_COMPILATION_NAME }.all { compilation -> - configureTestsRun(testRun, compilation) - } - } - - private fun configureTestsRun(testRun: KotlinJsPlatformTestRun, compilation: KotlinJsCompilation) { - fun KotlinJsPlatformTestRun.subtargetTestTaskName(): String = disambiguateCamelCased( - lowerCamelCaseName( - name.takeIf { it != KotlinTargetWithTests.DEFAULT_TEST_RUN_NAME }, - AbstractKotlinTargetConfigurator.testTaskNameSuffix - ) - ) - - val testJs = project.registerTask( - testRun.subtargetTestTaskName(), - listOf(compilation) - ) { testJs -> - val compileTask = compilation.compileTaskProvider - - testJs.group = LifecycleBasePlugin.VERIFICATION_GROUP - testJs.description = testTaskDescription - - val compileOutputFile = compileTask.flatMap { it.outputFileProperty } - testJs.inputFileProperty.fileProvider(compileOutputFile) - - testJs.dependsOn( - nodeJsTaskProviders.npmInstallTaskProvider, - nodeJsTaskProviders.storeYarnLockTaskProvider, - compileTask, - nodeJsTaskProviders.nodeJsSetupTaskProvider - ) - - testJs.onlyIf { - compileOutputFile.get().exists() - } - - testJs.targetName = listOfNotNull(target.disambiguationClassifier, disambiguationClassifier) - .takeIf { it.isNotEmpty() } - ?.joinToString() - - testJs.configureConventions() - } - - testRun.executionTask = testJs - - target.testRuns.matching { it.name == testRun.name }.all { parentTestRun -> - target.project.kotlinTestRegistry.registerTestTask( - testJs, - parentTestRun.executionTask - ) - } - - project.whenEvaluated { - testJs.configure { - if (it.testFramework == null) { - configureDefaultTestFramework(it) - } - - if (it.enabled) { - nodeJs.taskRequirements.addTaskRequirements(it) - } - } - } - } - - protected abstract fun configureDefaultTestFramework(testTask: KotlinJsTest) - - private fun configureMain() { - target.compilations.all { compilation -> - if (compilation.isMain()) { - configureMain(compilation) - } - } - } - - protected abstract fun configureMain(compilation: KotlinJsCompilation) - - internal inline fun registerSubTargetTask( - name: String, - args: List = emptyList(), - noinline body: (T) -> (Unit) - ): TaskProvider = - project.registerTask(name, args) { - it.group = taskGroupName - body(it) - } - - companion object { - const val RUN_TASK_NAME = "run" - } -} +@Deprecated("The Kotlin/JS legacy target is deprecated and its support completely discontinued", level = DeprecationLevel.WARNING) +abstract class KotlinJsSubTarget : KotlinJsSubTargetDsl \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/subtargets/KotlinNodeJs.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/subtargets/KotlinNodeJs.kt index b59d8621d2a..983209a3e49 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/subtargets/KotlinNodeJs.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/subtargets/KotlinNodeJs.kt @@ -5,54 +5,10 @@ package org.jetbrains.kotlin.gradle.targets.js.subtargets -import org.gradle.api.Action -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation -import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget -import org.jetbrains.kotlin.gradle.targets.js.dsl.Distribution -import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalDistributionDsl import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsNodeDsl -import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsExec -import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest -import org.jetbrains.kotlin.gradle.tasks.dependsOn -import org.jetbrains.kotlin.gradle.tasks.withType -import javax.inject.Inject -abstract class KotlinNodeJs @Inject constructor(target: KotlinJsTarget) : - KotlinJsSubTarget(target, "node"), - KotlinJsNodeDsl { - override val testTaskDescription: String - get() = "Run all ${target.name} tests inside nodejs using the builtin test framework" - - private val runTaskName = disambiguateCamelCased("run") - - override fun runTask(body: Action) { - project.tasks.withType().named(runTaskName).configure(body) - } - - @ExperimentalDistributionDsl - override fun distribution(body: Action) { - TODO("Not yet implemented") - } - - override fun testTask(body: Action) { - super.testTask(body) - } - - override fun configureDefaultTestFramework(testTask: KotlinJsTest) { - testTask.useMocha { } - } - - override fun configureMain(compilation: KotlinJsCompilation) { - configureRun(compilation) - } - - private fun configureRun( - compilation: KotlinJsCompilation - ) { - val runTaskHolder = NodeJsExec.create(compilation, disambiguateCamelCased(RUN_TASK_NAME)) { - group = taskGroupName - inputFileProperty.fileProvider(compilation.compileKotlinTaskProvider.flatMap { it.outputFileProperty }) - } - target.runTask.dependsOn(runTaskHolder) - } -} \ No newline at end of file +@Suppress("DEPRECATION") +@Deprecated("The Kotlin/JS legacy target is deprecated and its support completely discontinued", level = DeprecationLevel.HIDDEN) +abstract class KotlinNodeJs : + KotlinJsSubTarget(), + KotlinJsNodeDsl \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/KotlinHierarchyBuilderTest.kt b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/KotlinHierarchyBuilderTest.kt index 8dc4ad90700..6fe87977feb 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/KotlinHierarchyBuilderTest.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/KotlinHierarchyBuilderTest.kt @@ -9,7 +9,6 @@ package org.jetbrains.kotlin.gradle.unitTests import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension import org.jetbrains.kotlin.gradle.plugin.KotlinHierarchyBuilder -import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsTargetPreset import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmWithJavaTargetPreset import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTargetPreset import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinWasmTargetPreset @@ -28,7 +27,6 @@ class KotlinHierarchyBuilderTest { buildProjectWithMPP().multiplatformExtension.presets // JS targets are special and therefore are only handled manually using `withJs()` - .filter { it !is KotlinJsTargetPreset } .filter { it !is KotlinJsIrTargetPreset } .filter { it !is KotlinWasmTargetPreset }