Wizard: correctly add Kotlin dependencies to singleplatform modules with gradle dsl build system
#KT-35695 fixed
This commit is contained in:
+1
-2
@@ -15,9 +15,8 @@ repositories {
|
||||
dependencies {
|
||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||
implementation 'androidx.core:core-ktx:1.1.0'
|
||||
implementation kotlin('stdlib-jdk7')
|
||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||
implementation kotlin('stdlib-jdk8')
|
||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7'
|
||||
}
|
||||
android {
|
||||
compileSdkVersion 29
|
||||
|
||||
+1
-1
@@ -8,5 +8,5 @@ repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
implementation kotlin('stdlib-jdk8')
|
||||
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
|
||||
}
|
||||
+11
-3
@@ -113,6 +113,8 @@ abstract class KotlinLibraryDependencyIR(
|
||||
override val version: Version,
|
||||
override val dependencyType: DependencyType
|
||||
) : LibraryDependencyIR {
|
||||
abstract val isInMppModule: Boolean
|
||||
|
||||
override val artifact: LibraryArtifact
|
||||
get() = MavenArtifact(
|
||||
MAVEN_CENTRAL,
|
||||
@@ -123,9 +125,13 @@ abstract class KotlinLibraryDependencyIR(
|
||||
override fun BuildFilePrinter.render() {
|
||||
when (this) {
|
||||
is GradlePrinter -> call(dependencyType.gradleName) {
|
||||
+"kotlin("
|
||||
+artifactName.quotified
|
||||
+")"
|
||||
if (GradlePrinter.GradleDsl.KOTLIN == dsl || isInMppModule) {
|
||||
+"kotlin("
|
||||
+artifactName.quotified
|
||||
+")"
|
||||
} else {
|
||||
+"org.jetbrains.kotlin:kotlin-$artifactName".quotified
|
||||
}
|
||||
}
|
||||
is MavenPrinter -> node("dependency") {
|
||||
singleLineNode("groupId") { +"org.jetbrains.kotlin" }
|
||||
@@ -144,6 +150,7 @@ abstract class KotlinLibraryDependencyIR(
|
||||
|
||||
data class KotlinStdlibDependencyIR(
|
||||
val type: StdlibType,
|
||||
override val isInMppModule: Boolean,
|
||||
override val version: Version,
|
||||
override val dependencyType: DependencyType
|
||||
) : KotlinLibraryDependencyIR(type.artifact, version, dependencyType) {
|
||||
@@ -152,6 +159,7 @@ data class KotlinStdlibDependencyIR(
|
||||
|
||||
data class KotlinArbitraryDependencyIR(
|
||||
val name: String,
|
||||
override val isInMppModule: Boolean,
|
||||
override val version: Version,
|
||||
override val dependencyType: DependencyType
|
||||
) : KotlinLibraryDependencyIR(name, version, dependencyType) {
|
||||
|
||||
+12
-2
@@ -105,7 +105,12 @@ class ModulesToIRsConverter(
|
||||
+configurator.createModuleIRs(data, module)
|
||||
addIfNotNull(
|
||||
configurator.createStdlibType(data, module)?.let { stdlibType ->
|
||||
KotlinStdlibDependencyIR(stdlibType, kotlinVersion, DependencyType.MAIN)
|
||||
KotlinStdlibDependencyIR(
|
||||
type = stdlibType,
|
||||
isInMppModule = false,
|
||||
version = kotlinVersion,
|
||||
dependencyType = DependencyType.MAIN
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -179,7 +184,12 @@ class ModulesToIRsConverter(
|
||||
if (sourceset.sourcesetType == SourcesetType.main) {
|
||||
addIfNotNull(
|
||||
target.configurator.createStdlibType(data, target)?.let { stdlibType ->
|
||||
KotlinStdlibDependencyIR(stdlibType, data.kotlinVersion, DependencyType.MAIN)
|
||||
KotlinStdlibDependencyIR(
|
||||
type = stdlibType,
|
||||
isInMppModule = true,
|
||||
version = data.kotlinVersion,
|
||||
dependencyType = DependencyType.MAIN
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
+3
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.*
|
||||
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.KotlinPlugin
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.ModuleType
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.ModuleKind
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.SourcesetType
|
||||
|
||||
class KotlinTestTemplate : Template() {
|
||||
@@ -29,6 +30,8 @@ class KotlinTestTemplate : Template() {
|
||||
framework.reference.settingValue.dependencyNames.map { dependencyName ->
|
||||
KotlinArbitraryDependencyIR(
|
||||
dependencyName,
|
||||
isInMppModule = sourceset.original.parent?.kind
|
||||
?.let { it == ModuleKind.multiplatform || it == ModuleKind.target } != false,
|
||||
version = KotlinPlugin::version.settingValue,
|
||||
dependencyType = DependencyType.MAIN
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user