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 {
|
dependencies {
|
||||||
implementation("androidx.appcompat:appcompat:1.1.0")
|
implementation("androidx.appcompat:appcompat:1.1.0")
|
||||||
implementation("androidx.core:core-ktx:1.1.0")
|
implementation("androidx.core:core-ktx:1.1.0")
|
||||||
implementation(kotlin("stdlib-jdk7"))
|
|
||||||
implementation("androidx.constraintlayout:constraintlayout:1.1.3")
|
implementation("androidx.constraintlayout:constraintlayout:1.1.3")
|
||||||
implementation(kotlin("stdlib-jdk8"))
|
implementation(kotlin("stdlib-jdk7"))
|
||||||
}
|
}
|
||||||
android {
|
android {
|
||||||
compileSdkVersion(29)
|
compileSdkVersion(29)
|
||||||
|
|||||||
+1
-1
@@ -46,7 +46,7 @@
|
|||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains.kotlin</groupId>
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
<artifactId>kotlin-stdlib</artifactId>
|
<artifactId>kotlin-stdlib-jdk8</artifactId>
|
||||||
<version>1.3.61</version>
|
<version>1.3.61</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
+32
-10
@@ -1,6 +1,5 @@
|
|||||||
package org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem
|
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.ir.buildsystem.gradle.GradleIR
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.library.LibraryArtifact
|
import org.jetbrains.kotlin.tools.projectWizard.library.LibraryArtifact
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.library.MavenArtifact
|
import org.jetbrains.kotlin.tools.projectWizard.library.MavenArtifact
|
||||||
@@ -109,8 +108,8 @@ data class ArtifactBasedLibraryDependencyIR(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
data class KotlinLibraryDependencyIR(
|
abstract class KotlinLibraryDependencyIR(
|
||||||
val name: String,
|
val artifactName: String,
|
||||||
override val version: Version,
|
override val version: Version,
|
||||||
override val dependencyType: DependencyType
|
override val dependencyType: DependencyType
|
||||||
) : LibraryDependencyIR {
|
) : LibraryDependencyIR {
|
||||||
@@ -118,22 +117,22 @@ data class KotlinLibraryDependencyIR(
|
|||||||
get() = MavenArtifact(
|
get() = MavenArtifact(
|
||||||
MAVEN_CENTRAL,
|
MAVEN_CENTRAL,
|
||||||
"org.jetbrains.kotlin",
|
"org.jetbrains.kotlin",
|
||||||
"kotlin-$name"
|
"kotlin-$artifactName"
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun withDependencyType(type: DependencyType): KotlinLibraryDependencyIR =
|
|
||||||
copy(dependencyType = type)
|
|
||||||
|
|
||||||
override fun BuildFilePrinter.render() {
|
override fun BuildFilePrinter.render() {
|
||||||
when (this) {
|
when (this) {
|
||||||
is GradlePrinter -> call(dependencyType.gradleName) {
|
is GradlePrinter -> call(dependencyType.gradleName) {
|
||||||
+"kotlin("
|
+"kotlin("
|
||||||
+name.quotified
|
+artifactName.quotified
|
||||||
+")"
|
+")"
|
||||||
}
|
}
|
||||||
is MavenPrinter -> node("dependency") {
|
is MavenPrinter -> node("dependency") {
|
||||||
singleLineNode("groupId") { +"org.jetbrains.kotlin" }
|
singleLineNode("groupId") { +"org.jetbrains.kotlin" }
|
||||||
singleLineNode("artifactId") { +"kotlin-stdlib" }
|
singleLineNode("artifactId") {
|
||||||
|
+"kotlin-"
|
||||||
|
+artifactName
|
||||||
|
}
|
||||||
singleLineNode("version") { +version.toString() }
|
singleLineNode("version") { +version.toString() }
|
||||||
if (dependencyType == DependencyType.TEST) {
|
if (dependencyType == DependencyType.TEST) {
|
||||||
singleLineNode("scope") { +"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
|
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
|
dependencyType = DependencyType.MAIN
|
||||||
)
|
)
|
||||||
|
|
||||||
+KotlinLibraryDependencyIR("stdlib-jdk7", configurationData.kotlinVersion, DependencyType.MAIN)
|
|
||||||
|
|
||||||
+ArtifactBasedLibraryDependencyIR(
|
+ArtifactBasedLibraryDependencyIR(
|
||||||
MavenArtifact(DefaultRepository.GOOGLE, "androidx.constraintlayout", "constraintlayout"),
|
MavenArtifact(DefaultRepository.GOOGLE, "androidx.constraintlayout", "constraintlayout"),
|
||||||
version = Version.fromString("1.1.3"),
|
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<*, *>> =
|
override val settings: List<ModuleConfiguratorSetting<*, *>> =
|
||||||
listOf(androidSdkPath)
|
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.core.entity.*
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.BuildSystemIR
|
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.KotlinBuildSystemPluginIR
|
||||||
|
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.StdlibType
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.phases.GenerationPhase
|
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.ModuleConfigurationData
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.ModuleType
|
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.DisplayableSettingItem
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.*
|
import org.jetbrains.kotlin.tools.projectWizard.settings.buildsystem.*
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.settings.version.Version
|
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> =
|
fun createModuleIRs(configurationData: ModuleConfigurationData, module: Module): List<BuildSystemIR> =
|
||||||
emptyList()
|
emptyList()
|
||||||
|
|
||||||
|
fun createStdlibType(configurationData: ModuleConfigurationData, module: Module): StdlibType? =
|
||||||
|
moduleType.correspondingStdlib()
|
||||||
|
|
||||||
fun createRootBuildFileIrs(configurationData: ModuleConfigurationData): List<BuildSystemIR> = emptyList()
|
fun createRootBuildFileIrs(configurationData: ModuleConfigurationData): List<BuildSystemIR> = emptyList()
|
||||||
fun createKotlinPluginIR(configurationData: ModuleConfigurationData, module: Module): KotlinBuildSystemPluginIR? =
|
fun createKotlinPluginIR(configurationData: ModuleConfigurationData, module: Module): KotlinBuildSystemPluginIR? =
|
||||||
null
|
null
|
||||||
|
|||||||
+4
-24
@@ -51,30 +51,10 @@ class KotlinPlugin(context: Context) : Plugin(context) {
|
|||||||
runBefore(BuildSystemPlugin::createModules)
|
runBefore(BuildSystemPlugin::createModules)
|
||||||
runAfter(StructurePlugin::createProjectDir)
|
runAfter(StructurePlugin::createProjectDir)
|
||||||
withAction {
|
withAction {
|
||||||
computeM {
|
BuildSystemPlugin::buildFiles.update {
|
||||||
BuildSystemPlugin::buildFiles.update {
|
val modules = KotlinPlugin::modules.settingValue
|
||||||
val modules = KotlinPlugin::modules.settingValue
|
val (buildFiles) = createBuildFiles(modules)
|
||||||
val (buildFiles) = createBuildFiles(modules)
|
buildFiles.map { it.withIrs(RepositoryIR(DefaultRepository.MAVEN_CENTRAL)) }.asSuccess()
|
||||||
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()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-4
@@ -1,5 +1,7 @@
|
|||||||
package org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin
|
package org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.tools.projectWizard.ir.buildsystem.StdlibType
|
||||||
|
|
||||||
@Suppress("EnumEntryName")
|
@Suppress("EnumEntryName")
|
||||||
enum class ModuleType(val projectTypeName: String) {
|
enum class ModuleType(val projectTypeName: String) {
|
||||||
jvm("Kotlin/JVM"),
|
jvm("Kotlin/JVM"),
|
||||||
@@ -27,10 +29,10 @@ enum class ModuleSubType(val moduleType: ModuleType) {
|
|||||||
common(ModuleType.common)
|
common(ModuleType.common)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ModuleType.correspondingStdlibName() = when (this) {
|
fun ModuleType.correspondingStdlib(): StdlibType? = when (this) {
|
||||||
ModuleType.jvm -> "stdlib-jdk8"
|
ModuleType.jvm -> StdlibType.StdlibJdk8
|
||||||
ModuleType.js -> "stdlib-js"
|
ModuleType.js -> StdlibType.StdlibJs
|
||||||
ModuleType.native -> null
|
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)
|
val modulePath = calculatePathForModule(module, state.parentPath)
|
||||||
taskRunningContext.mutateProjectStructureByModuleConfigurator(module, modulePath)
|
taskRunningContext.mutateProjectStructureByModuleConfigurator(module, modulePath)
|
||||||
val configurator = module.configurator
|
val configurator = module.configurator
|
||||||
val dependenciesIRs = module.sourcesets.flatMap { sourceset ->
|
val dependenciesIRs = buildList<BuildSystemIR> {
|
||||||
sourceset.dependencies.map { it.toIR(sourceset.sourcesetType.toDependencyType()) }
|
+module.sourcesets.flatMap { sourceset ->
|
||||||
} + configurator.createModuleIRs(data, module)
|
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(
|
val moduleIr = SingleplatformModuleIR(
|
||||||
module.name,
|
module.name,
|
||||||
@@ -146,19 +154,8 @@ class ModulesToIRsConverter(
|
|||||||
(subModule.configurator as TargetConfigurator).createTargetIrs(subModule)
|
(subModule.configurator as TargetConfigurator).createTargetIrs(subModule)
|
||||||
}
|
}
|
||||||
|
|
||||||
val sourcesetIrs = module.subModules.flatMap { target ->
|
val sourcesetsIrs = module.subModules.flatMap { target ->
|
||||||
target.sourcesets.map { sourceset ->
|
createTargetSourceset(target, modulePath)
|
||||||
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
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return BuildFileIR(
|
return BuildFileIR(
|
||||||
@@ -166,7 +163,7 @@ class ModulesToIRsConverter(
|
|||||||
modulePath,
|
modulePath,
|
||||||
MultiplatformModulesStructureIR(
|
MultiplatformModulesStructureIR(
|
||||||
targetIrs,
|
targetIrs,
|
||||||
sourcesetIrs,
|
sourcesetsIrs,
|
||||||
emptyList()
|
emptyList()
|
||||||
),
|
),
|
||||||
pomIr,
|
pomIr,
|
||||||
@@ -174,6 +171,30 @@ class ModulesToIRsConverter(
|
|||||||
).asSingletonList().asSuccess()
|
).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(
|
private fun TaskRunningContext.mutateProjectStructureByModuleConfigurator(
|
||||||
module: Module,
|
module: Module,
|
||||||
modulePath: Path
|
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.TaskRunningContext
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.TemplateSetting
|
import org.jetbrains.kotlin.tools.projectWizard.core.entity.TemplateSetting
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.TemplateSettingReference
|
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.*
|
||||||
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.phases.GenerationPhase
|
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.KotlinPlugin
|
||||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.ModuleType
|
import org.jetbrains.kotlin.tools.projectWizard.plugins.kotlin.ModuleType
|
||||||
@@ -30,7 +27,7 @@ class KotlinTestTemplate : Template() {
|
|||||||
override fun TaskRunningContext.getRequiredLibraries(sourceset: SourcesetIR): List<DependencyIR> =
|
override fun TaskRunningContext.getRequiredLibraries(sourceset: SourcesetIR): List<DependencyIR> =
|
||||||
withSettingsOf(sourceset.original) {
|
withSettingsOf(sourceset.original) {
|
||||||
framework.reference.settingValue.dependencyNames.map { dependencyName ->
|
framework.reference.settingValue.dependencyNames.map { dependencyName ->
|
||||||
KotlinLibraryDependencyIR(
|
KotlinArbitraryDependencyIR(
|
||||||
dependencyName,
|
dependencyName,
|
||||||
version = KotlinPlugin::version.settingValue,
|
version = KotlinPlugin::version.settingValue,
|
||||||
dependencyType = DependencyType.MAIN
|
dependencyType = DependencyType.MAIN
|
||||||
|
|||||||
Reference in New Issue
Block a user