Wizard: fix adding invalid dependencies for maven build files
#KT-35711 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(kotlin("stdlib-jdk7"))
|
||||
}
|
||||
android {
|
||||
compileSdkVersion(29)
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<artifactId>kotlin-stdlib-jdk8</artifactId>
|
||||
<version>1.3.61</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
+32
-10
@@ -1,6 +1,5 @@
|
||||
package org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem
|
||||
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.safeAs
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.gradle.GradleIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.library.LibraryArtifact
|
||||
import org.jetbrains.kotlin.tools.projectWizard.library.MavenArtifact
|
||||
@@ -109,8 +108,8 @@ data class ArtifactBasedLibraryDependencyIR(
|
||||
}
|
||||
|
||||
|
||||
data class KotlinLibraryDependencyIR(
|
||||
val name: String,
|
||||
abstract class KotlinLibraryDependencyIR(
|
||||
val artifactName: String,
|
||||
override val version: Version,
|
||||
override val dependencyType: DependencyType
|
||||
) : LibraryDependencyIR {
|
||||
@@ -118,22 +117,22 @@ data class KotlinLibraryDependencyIR(
|
||||
get() = MavenArtifact(
|
||||
MAVEN_CENTRAL,
|
||||
"org.jetbrains.kotlin",
|
||||
"kotlin-$name"
|
||||
"kotlin-$artifactName"
|
||||
)
|
||||
|
||||
override fun withDependencyType(type: DependencyType): KotlinLibraryDependencyIR =
|
||||
copy(dependencyType = type)
|
||||
|
||||
override fun BuildFilePrinter.render() {
|
||||
when (this) {
|
||||
is GradlePrinter -> call(dependencyType.gradleName) {
|
||||
+"kotlin("
|
||||
+name.quotified
|
||||
+artifactName.quotified
|
||||
+")"
|
||||
}
|
||||
is MavenPrinter -> node("dependency") {
|
||||
singleLineNode("groupId") { +"org.jetbrains.kotlin" }
|
||||
singleLineNode("artifactId") { +"kotlin-stdlib" }
|
||||
singleLineNode("artifactId") {
|
||||
+"kotlin-"
|
||||
+artifactName
|
||||
}
|
||||
singleLineNode("version") { +version.toString() }
|
||||
if (dependencyType == DependencyType.TEST) {
|
||||
singleLineNode("scope") { +"test" }
|
||||
@@ -143,5 +142,28 @@ data class KotlinLibraryDependencyIR(
|
||||
}
|
||||
}
|
||||
|
||||
data class KotlinStdlibDependencyIR(
|
||||
val type: StdlibType,
|
||||
override val version: Version,
|
||||
override val dependencyType: DependencyType
|
||||
) : KotlinLibraryDependencyIR(type.artifact, version, dependencyType) {
|
||||
override fun withDependencyType(type: DependencyType): KotlinStdlibDependencyIR = copy(dependencyType = type)
|
||||
}
|
||||
|
||||
data class KotlinArbitraryDependencyIR(
|
||||
val name: String,
|
||||
override val version: Version,
|
||||
override val dependencyType: DependencyType
|
||||
) : KotlinLibraryDependencyIR(name, version, dependencyType) {
|
||||
override fun withDependencyType(type: DependencyType): KotlinArbitraryDependencyIR = copy(dependencyType = type)
|
||||
}
|
||||
|
||||
enum class StdlibType(val artifact: String) {
|
||||
StdlibJdk7("stdlib-jdk7"),
|
||||
StdlibJdk8("stdlib-jdk8"),
|
||||
StdlibJs("stdlib-js"),
|
||||
StdlibCommon("stdlib-common"),
|
||||
}
|
||||
|
||||
val LibraryDependencyIR.isKotlinStdlib
|
||||
get() = safeAs<KotlinLibraryDependencyIR>()?.name?.contains("stdlib") == true
|
||||
get() = this is KotlinStdlibDependencyIR
|
||||
+3
-2
@@ -106,8 +106,6 @@ object AndroidSinglePlatformModuleConfigurator : ModuleConfiguratorWithSettings(
|
||||
dependencyType = DependencyType.MAIN
|
||||
)
|
||||
|
||||
+KotlinLibraryDependencyIR("stdlib-jdk7", configurationData.kotlinVersion, DependencyType.MAIN)
|
||||
|
||||
+ArtifactBasedLibraryDependencyIR(
|
||||
MavenArtifact(DefaultRepository.GOOGLE, "androidx.constraintlayout", "constraintlayout"),
|
||||
version = Version.fromString("1.1.3"),
|
||||
@@ -115,6 +113,9 @@ object AndroidSinglePlatformModuleConfigurator : ModuleConfiguratorWithSettings(
|
||||
)
|
||||
}
|
||||
|
||||
override fun createStdlibType(configurationData: ModuleConfigurationData, module: Module): StdlibType? =
|
||||
StdlibType.StdlibJdk7
|
||||
|
||||
override val settings: List<ModuleConfiguratorSetting<*, *>> =
|
||||
listOf(androidSdkPath)
|
||||
|
||||
|
||||
+5
@@ -7,9 +7,11 @@ import org.jetbrains.kotlin.tools.projectWizard.core.cached
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.*
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.BuildSystemIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.KotlinBuildSystemPluginIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.StdlibType
|
||||
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.ModuleConfigurationData
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.ModuleType
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.correspondingStdlib
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.DisplayableSettingItem
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.*
|
||||
import org.jetbrains.kotlin.tools.projectWizard.settings.version.Version
|
||||
@@ -170,6 +172,9 @@ interface ModuleConfigurator : DisplayableSettingItem, EntitiesOwnerDescriptor {
|
||||
fun createModuleIRs(configurationData: ModuleConfigurationData, module: Module): List<BuildSystemIR> =
|
||||
emptyList()
|
||||
|
||||
fun createStdlibType(configurationData: ModuleConfigurationData, module: Module): StdlibType? =
|
||||
moduleType.correspondingStdlib()
|
||||
|
||||
fun createRootBuildFileIrs(configurationData: ModuleConfigurationData): List<BuildSystemIR> = emptyList()
|
||||
fun createKotlinPluginIR(configurationData: ModuleConfigurationData, module: Module): KotlinBuildSystemPluginIR? =
|
||||
null
|
||||
|
||||
+4
-24
@@ -51,30 +51,10 @@ class KotlinPlugin(context: Context) : Plugin(context) {
|
||||
runBefore(BuildSystemPlugin::createModules)
|
||||
runAfter(StructurePlugin::createProjectDir)
|
||||
withAction {
|
||||
computeM {
|
||||
BuildSystemPlugin::buildFiles.update {
|
||||
val modules = KotlinPlugin::modules.settingValue
|
||||
val (buildFiles) = createBuildFiles(modules)
|
||||
buildFiles.map { it.withIrs(RepositoryIR(DefaultRepository.MAVEN_CENTRAL)) }.asSuccess()
|
||||
}.ensure()
|
||||
|
||||
updateModules { module ->
|
||||
val needLibrary = when (module) {
|
||||
is SingleplatformModuleIR -> true
|
||||
is SourcesetModuleIR -> module.sourcesetType == SourcesetType.main
|
||||
}
|
||||
val libraryName = module.type.correspondingStdlibName()
|
||||
when {
|
||||
needLibrary && libraryName != null -> module.withIrs(
|
||||
KotlinLibraryDependencyIR(
|
||||
libraryName,
|
||||
KotlinPlugin::version.settingValue,
|
||||
DependencyType.MAIN
|
||||
)
|
||||
)
|
||||
else -> module
|
||||
}.asSuccess()
|
||||
}
|
||||
BuildSystemPlugin::buildFiles.update {
|
||||
val modules = KotlinPlugin::modules.settingValue
|
||||
val (buildFiles) = createBuildFiles(modules)
|
||||
buildFiles.map { it.withIrs(RepositoryIR(DefaultRepository.MAVEN_CENTRAL)) }.asSuccess()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-4
@@ -1,5 +1,7 @@
|
||||
package org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin
|
||||
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.StdlibType
|
||||
|
||||
@Suppress("EnumEntryName")
|
||||
enum class ModuleType(val projectTypeName: String) {
|
||||
jvm("Kotlin/JVM"),
|
||||
@@ -27,10 +29,10 @@ enum class ModuleSubType(val moduleType: ModuleType) {
|
||||
common(ModuleType.common)
|
||||
}
|
||||
|
||||
fun ModuleType.correspondingStdlibName() = when (this) {
|
||||
ModuleType.jvm -> "stdlib-jdk8"
|
||||
ModuleType.js -> "stdlib-js"
|
||||
fun ModuleType.correspondingStdlib(): StdlibType? = when (this) {
|
||||
ModuleType.jvm -> StdlibType.StdlibJdk8
|
||||
ModuleType.js -> StdlibType.StdlibJs
|
||||
ModuleType.native -> null
|
||||
ModuleType.common -> "stdlib-common"
|
||||
ModuleType.common -> StdlibType.StdlibCommon
|
||||
}
|
||||
|
||||
|
||||
+38
-17
@@ -98,9 +98,17 @@ class ModulesToIRsConverter(
|
||||
val modulePath = calculatePathForModule(module, state.parentPath)
|
||||
taskRunningContext.mutateProjectStructureByModuleConfigurator(module, modulePath)
|
||||
val configurator = module.configurator
|
||||
val dependenciesIRs = module.sourcesets.flatMap { sourceset ->
|
||||
sourceset.dependencies.map { it.toIR(sourceset.sourcesetType.toDependencyType()) }
|
||||
} + configurator.createModuleIRs(data, module)
|
||||
val dependenciesIRs = buildList<BuildSystemIR> {
|
||||
+module.sourcesets.flatMap { sourceset ->
|
||||
sourceset.dependencies.map { it.toIR(sourceset.sourcesetType.toDependencyType()) }
|
||||
}
|
||||
+configurator.createModuleIRs(data, module)
|
||||
addIfNotNull(
|
||||
configurator.createStdlibType(data, module)?.let { stdlibType ->
|
||||
KotlinStdlibDependencyIR(stdlibType, kotlinVersion, DependencyType.MAIN)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
val moduleIr = SingleplatformModuleIR(
|
||||
module.name,
|
||||
@@ -146,19 +154,8 @@ class ModulesToIRsConverter(
|
||||
(subModule.configurator as TargetConfigurator).createTargetIrs(subModule)
|
||||
}
|
||||
|
||||
val sourcesetIrs = module.subModules.flatMap { target ->
|
||||
target.sourcesets.map { sourceset ->
|
||||
val sourcesetName = target.name + sourceset.sourcesetType.name.capitalize()
|
||||
SourcesetModuleIR(
|
||||
sourcesetName,
|
||||
modulePath / Defaults.SRC_DIR / sourcesetName,
|
||||
sourceset.dependencies.map { it.toIR(DependencyType.MAIN) },
|
||||
sourceset.containingModuleType,
|
||||
sourceset.sourcesetType,
|
||||
sourceset.template,
|
||||
sourceset
|
||||
)
|
||||
}
|
||||
val sourcesetsIrs = module.subModules.flatMap { target ->
|
||||
createTargetSourceset(target, modulePath)
|
||||
}
|
||||
|
||||
return BuildFileIR(
|
||||
@@ -166,7 +163,7 @@ class ModulesToIRsConverter(
|
||||
modulePath,
|
||||
MultiplatformModulesStructureIR(
|
||||
targetIrs,
|
||||
sourcesetIrs,
|
||||
sourcesetsIrs,
|
||||
emptyList()
|
||||
),
|
||||
pomIr,
|
||||
@@ -174,6 +171,30 @@ class ModulesToIRsConverter(
|
||||
).asSingletonList().asSuccess()
|
||||
}
|
||||
|
||||
private fun createTargetSourceset(target: Module, modulePath: Path): List<SourcesetModuleIR> =
|
||||
target.sourcesets.map { sourceset ->
|
||||
val sourcesetName = target.name + sourceset.sourcesetType.name.capitalize()
|
||||
val sourcesetIrs = buildList<BuildSystemIR> {
|
||||
+sourceset.dependencies.map { it.toIR(sourceset.sourcesetType.toDependencyType()) }
|
||||
if (sourceset.sourcesetType == SourcesetType.main) {
|
||||
addIfNotNull(
|
||||
target.configurator.createStdlibType(data, target)?.let { stdlibType ->
|
||||
KotlinStdlibDependencyIR(stdlibType, data.kotlinVersion, DependencyType.MAIN)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
SourcesetModuleIR(
|
||||
sourcesetName,
|
||||
modulePath / Defaults.SRC_DIR / sourcesetName,
|
||||
sourcesetIrs,
|
||||
sourceset.containingModuleType,
|
||||
sourceset.sourcesetType,
|
||||
sourceset.template,
|
||||
sourceset
|
||||
)
|
||||
}
|
||||
|
||||
private fun TaskRunningContext.mutateProjectStructureByModuleConfigurator(
|
||||
module: Module,
|
||||
modulePath: Path
|
||||
|
||||
+2
-5
@@ -6,10 +6,7 @@ import org.jetbrains.kotlin.tools.projectWizard.core.*
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.TaskRunningContext
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.TemplateSetting
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.TemplateSettingReference
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.DependencyIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.DependencyType
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.KotlinLibraryDependencyIR
|
||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.SourcesetIR
|
||||
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
|
||||
@@ -30,7 +27,7 @@ class KotlinTestTemplate : Template() {
|
||||
override fun TaskRunningContext.getRequiredLibraries(sourceset: SourcesetIR): List<DependencyIR> =
|
||||
withSettingsOf(sourceset.original) {
|
||||
framework.reference.settingValue.dependencyNames.map { dependencyName ->
|
||||
KotlinLibraryDependencyIR(
|
||||
KotlinArbitraryDependencyIR(
|
||||
dependencyName,
|
||||
version = KotlinPlugin::version.settingValue,
|
||||
dependencyType = DependencyType.MAIN
|
||||
|
||||
Reference in New Issue
Block a user