mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-04-05 08:31:31 +00:00
Add Kotlin/MPP to Gradle group of New Project Wizards #KT-32105 Fixed
This commit is contained in:
@@ -289,8 +289,8 @@ open class GradleKotlinJSNodeFrameworkSupportProvider(
|
||||
override fun getDescription() = "A Kotlin library or application targeting JavaScript for Node.js"
|
||||
}
|
||||
|
||||
class GradleKotlinMPPFrameworkSupportProvider : GradleKotlinFrameworkSupportProvider(
|
||||
"KOTLIN_MPP", "Kotlin (Multiplatform - Experimental)", KotlinIcons.MPP
|
||||
open class GradleKotlinMPPFrameworkSupportProvider : GradleKotlinFrameworkSupportProvider(
|
||||
"KOTLIN_MPP", "Kotlin/Multiplatform", KotlinIcons.MPP
|
||||
) {
|
||||
override fun getPluginId() = "org.jetbrains.kotlin.multiplatform"
|
||||
override fun getPluginExpression() = "id 'org.jetbrains.kotlin.multiplatform'"
|
||||
@@ -298,6 +298,38 @@ class GradleKotlinMPPFrameworkSupportProvider : GradleKotlinFrameworkSupportProv
|
||||
override fun getDependencies(sdk: Sdk?): List<String> = listOf()
|
||||
override fun getTestDependencies(): List<String> = listOf()
|
||||
|
||||
override fun getDescription() = "Kotlin multiplatform code"
|
||||
override fun getDescription() =
|
||||
"For sharing code between platforms (JVM, JS, Android, iOS, etc.)"
|
||||
|
||||
override fun addSupport(
|
||||
buildScriptData: BuildScriptDataBuilder,
|
||||
module: Module,
|
||||
sdk: Sdk?,
|
||||
specifyPluginVersionIfNeeded: Boolean,
|
||||
explicitPluginVersion: String?
|
||||
) {
|
||||
super.addSupport(buildScriptData, module, sdk, specifyPluginVersionIfNeeded, explicitPluginVersion)
|
||||
|
||||
buildScriptData.addOther(
|
||||
"""kotlin {
|
||||
/* Targets declarations omitted
|
||||
* Documentation: https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html */
|
||||
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
implementation kotlin('stdlib-common')
|
||||
}
|
||||
}
|
||||
commonTest {
|
||||
dependencies {
|
||||
implementation kotlin('test-common')
|
||||
implementation kotlin('test-annotations-common')
|
||||
}
|
||||
}
|
||||
}
|
||||
}"""
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,6 @@ abstract class KotlinDslGradleKotlinFrameworkSupportProvider(
|
||||
|
||||
buildScriptData
|
||||
.addPluginDefinitionInPluginsGroup(getPluginDefinition() + " version \"$kotlinVersion\"")
|
||||
.addDependencyNotation(getRuntimeLibrary(rootModel, null))
|
||||
} else {
|
||||
if (additionalRepository != null) {
|
||||
val repository = additionalRepository.toKotlinRepositorySnippet()
|
||||
@@ -95,7 +94,6 @@ abstract class KotlinDslGradleKotlinFrameworkSupportProvider(
|
||||
.addBuildscriptRepositoriesDefinition("mavenCentral()")
|
||||
// TODO: in gradle > 4.1 this could be single declaration e.g. 'val kotlin_version: String by extra { "1.1.11" }'
|
||||
.addBuildscriptPropertyDefinition("var $GSK_KOTLIN_VERSION_PROPERTY_NAME: String by extra\n $GSK_KOTLIN_VERSION_PROPERTY_NAME = \"$kotlinVersion\"")
|
||||
.addDependencyNotation(getRuntimeLibrary(rootModel, "\$$GSK_KOTLIN_VERSION_PROPERTY_NAME"))
|
||||
.addBuildscriptDependencyNotation(getKotlinGradlePluginClassPathSnippet())
|
||||
}
|
||||
|
||||
@@ -112,8 +110,6 @@ abstract class KotlinDslGradleKotlinFrameworkSupportProvider(
|
||||
|
||||
private fun RepositoryDescription.toKotlinRepositorySnippet() = "maven { setUrl(\"$url\") }"
|
||||
|
||||
protected abstract fun getRuntimeLibrary(rootModel: ModifiableRootModel, version: String?): String
|
||||
|
||||
protected abstract fun getOldSyntaxPluginDefinition(): String
|
||||
protected abstract fun getPluginDefinition(): String
|
||||
}
|
||||
@@ -124,7 +120,7 @@ class KotlinDslGradleKotlinJavaFrameworkSupportProvider :
|
||||
override fun getOldSyntaxPluginDefinition() = "plugin(\"${KotlinGradleModuleConfigurator.KOTLIN}\")"
|
||||
override fun getPluginDefinition() = "kotlin(\"jvm\")"
|
||||
|
||||
override fun getRuntimeLibrary(rootModel: ModifiableRootModel, version: String?) =
|
||||
private fun getRuntimeLibrary(rootModel: ModifiableRootModel, version: String?) =
|
||||
"implementation(${getKotlinModuleDependencySnippet(getStdlibArtifactId(rootModel.sdk, bundledRuntimeVersion()), version)})"
|
||||
|
||||
override fun addSupport(
|
||||
@@ -141,6 +137,11 @@ class KotlinDslGradleKotlinJavaFrameworkSupportProvider :
|
||||
.addImport("import org.jetbrains.kotlin.gradle.tasks.KotlinCompile")
|
||||
.addOther("tasks.withType<KotlinCompile> {\n kotlinOptions.jvmTarget = \"1.8\"\n}\n")
|
||||
}
|
||||
|
||||
if (buildScriptData.gradleVersion >= MIN_GRADLE_VERSION_FOR_NEW_PLUGIN_SYNTAX)
|
||||
buildScriptData.addDependencyNotation(getRuntimeLibrary(rootModel, null))
|
||||
else
|
||||
buildScriptData.addDependencyNotation(getRuntimeLibrary(rootModel, "\$$GSK_KOTLIN_VERSION_PROPERTY_NAME"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,12 +161,17 @@ abstract class AbstractKotlinDslGradleKotlinJSFrameworkSupportProvider(
|
||||
super.addSupport(projectId, module, rootModel, modifiableModelsProvider, buildScriptData)
|
||||
|
||||
buildScriptData.addOther("kotlin.target.$jsSubTargetName { }")
|
||||
|
||||
if (buildScriptData.gradleVersion >= MIN_GRADLE_VERSION_FOR_NEW_PLUGIN_SYNTAX)
|
||||
buildScriptData.addDependencyNotation(getRuntimeLibrary(rootModel, null))
|
||||
else
|
||||
buildScriptData.addDependencyNotation(getRuntimeLibrary(rootModel, "\$$GSK_KOTLIN_VERSION_PROPERTY_NAME"))
|
||||
}
|
||||
|
||||
override fun getOldSyntaxPluginDefinition(): String = "plugin(\"${KotlinJsGradleModuleConfigurator.KOTLIN_JS}\")"
|
||||
override fun getPluginDefinition(): String = "id(\"org.jetbrains.kotlin.js\")"
|
||||
|
||||
override fun getRuntimeLibrary(rootModel: ModifiableRootModel, version: String?) =
|
||||
private fun getRuntimeLibrary(rootModel: ModifiableRootModel, version: String?) =
|
||||
"implementation(${getKotlinModuleDependencySnippet(MAVEN_JS_STDLIB_ID.removePrefix("kotlin-"), version)})"
|
||||
}
|
||||
|
||||
@@ -180,3 +186,41 @@ class KotlinDslGradleKotlinJSNodeFrameworkSupportProvider :
|
||||
override val jsSubTargetName: String
|
||||
get() = "nodejs"
|
||||
}
|
||||
|
||||
class KotlinDslGradleKotlinMPPFrameworkSupportProvider :
|
||||
KotlinDslGradleKotlinFrameworkSupportProvider("KOTLIN_MPP", "Kotlin/Multiplatform", KotlinIcons.MPP) {
|
||||
|
||||
override fun getOldSyntaxPluginDefinition() = "plugin(\"org.jetbrains.kotlin.multiplatform\")"
|
||||
override fun getPluginDefinition() = "kotlin(\"multiplatform\")"
|
||||
|
||||
override fun addSupport(
|
||||
projectId: ProjectId,
|
||||
module: Module,
|
||||
rootModel: ModifiableRootModel,
|
||||
modifiableModelsProvider: ModifiableModelsProvider,
|
||||
buildScriptData: BuildScriptDataBuilder
|
||||
) {
|
||||
super.addSupport(projectId, module, rootModel, modifiableModelsProvider, buildScriptData)
|
||||
|
||||
buildScriptData.addOther(
|
||||
"""kotlin {
|
||||
/* Targets declarations omitted
|
||||
* Documentation: https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html */
|
||||
|
||||
sourceSets {
|
||||
val commonMain by getting {
|
||||
dependencies {
|
||||
implementation(kotlin("stdlib-common"))
|
||||
}
|
||||
}
|
||||
val commonTest by getting {
|
||||
dependencies {
|
||||
implementation(kotlin("test-common"))
|
||||
implementation(kotlin("test-annotations-common"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}"""
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
<idea-plugin>
|
||||
<extensions defaultExtensionNs="org.jetbrains.plugins.gradle">
|
||||
<frameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.GradleKotlinMPPFrameworkSupportProvider"/>
|
||||
<frameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.GradleKotlinJavaFrameworkSupportProvider"/>
|
||||
<frameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.GradleKotlinJSBrowserFrameworkSupportProvider"/>
|
||||
<frameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.GradleKotlinJSNodeFrameworkSupportProvider"/>
|
||||
<kotlinDslFrameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.KotlinDslGradleKotlinMPPFrameworkSupportProvider"/>
|
||||
<kotlinDslFrameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.KotlinDslGradleKotlinJavaFrameworkSupportProvider"/>
|
||||
<kotlinDslFrameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.KotlinDslGradleKotlinJSBrowserFrameworkSupportProvider"/>
|
||||
<kotlinDslFrameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.KotlinDslGradleKotlinJSNodeFrameworkSupportProvider"/>
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
<idea-plugin>
|
||||
<extensions defaultExtensionNs="org.jetbrains.plugins.gradle">
|
||||
<frameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.GradleKotlinMPPFrameworkSupportProvider"/>
|
||||
<frameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.GradleKotlinJavaFrameworkSupportProvider"/>
|
||||
<frameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.GradleKotlinJSBrowserFrameworkSupportProvider"/>
|
||||
<frameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.GradleKotlinJSNodeFrameworkSupportProvider"/>
|
||||
<kotlinDslFrameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.KotlinDslGradleKotlinMPPFrameworkSupportProvider"/>
|
||||
<kotlinDslFrameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.KotlinDslGradleKotlinJavaFrameworkSupportProvider"/>
|
||||
<kotlinDslFrameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.KotlinDslGradleKotlinJSBrowserFrameworkSupportProvider"/>
|
||||
<kotlinDslFrameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.KotlinDslGradleKotlinJSNodeFrameworkSupportProvider"/>
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
<idea-plugin>
|
||||
<extensions defaultExtensionNs="org.jetbrains.plugins.gradle">
|
||||
<frameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.GradleKotlinMPPFrameworkSupportProvider"/>
|
||||
<frameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.GradleKotlinJavaFrameworkSupportProvider"/>
|
||||
<frameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.GradleKotlinJSBrowserFrameworkSupportProvider"/>
|
||||
<frameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.GradleKotlinJSNodeFrameworkSupportProvider"/>
|
||||
<kotlinDslFrameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.KotlinDslGradleKotlinMPPFrameworkSupportProvider"/>
|
||||
<kotlinDslFrameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.KotlinDslGradleKotlinJavaFrameworkSupportProvider"/>
|
||||
<kotlinDslFrameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.KotlinDslGradleKotlinJSBrowserFrameworkSupportProvider"/>
|
||||
<kotlinDslFrameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.KotlinDslGradleKotlinJSNodeFrameworkSupportProvider"/>
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
<idea-plugin>
|
||||
<extensions defaultExtensionNs="org.jetbrains.plugins.gradle">
|
||||
<frameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.GradleKotlinMPPFrameworkSupportProvider"/>
|
||||
<frameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.GradleKotlinJavaFrameworkSupportProvider"/>
|
||||
<frameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.GradleKotlinJSBrowserFrameworkSupportProvider"/>
|
||||
<frameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.GradleKotlinJSNodeFrameworkSupportProvider"/>
|
||||
<kotlinDslFrameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.KotlinDslGradleKotlinMPPFrameworkSupportProvider"/>
|
||||
<kotlinDslFrameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.KotlinDslGradleKotlinJavaFrameworkSupportProvider"/>
|
||||
<kotlinDslFrameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.KotlinDslGradleKotlinJSBrowserFrameworkSupportProvider"/>
|
||||
<kotlinDslFrameworkSupport implementation="org.jetbrains.kotlin.idea.configuration.KotlinDslGradleKotlinJSNodeFrameworkSupportProvider"/>
|
||||
|
||||
Reference in New Issue
Block a user