From 3b13944daf52118e2226cad91a5f2144b8b295b1 Mon Sep 17 00:00:00 2001 From: Igor Demin Date: Mon, 26 Oct 2020 18:54:19 +0300 Subject: [PATCH 1/2] Fix multiplatform projects in IDEA / Android Studio Fixes: - https://github.com/JetBrains/compose-jb/issues/21 We need to move buildscript from settings.gradle.kts to build.gradle.kts See also https://youtrack.jetbrains.com/issue/KT-36331 - https://github.com/JetBrains/compose-jb/issues/22 kotlin("jvm") plugin doesn't work well with MPP modules. To fix this issue we need to use kotlin("multiplatform") even if we targeting single platform. See also https://youtrack.jetbrains.com/issue/KT-42823 --- examples/imageviewer/build.gradle.kts | 14 ++++++++ examples/imageviewer/desktop/build.gradle.kts | 17 +++++++--- .../kotlin/imageviewer/Main.kt | 0 examples/imageviewer/settings.gradle.kts | 14 -------- examples/issues/build.gradle.kts | 14 ++++++++ examples/issues/desktop/build.gradle.kts | 17 +++++++--- .../androidx/ui/examples/jetissues/Main.kt | 0 examples/issues/settings.gradle.kts | 14 -------- examples/todoapp/desktop/build.gradle.kts | 32 ++++++++++++------- .../kotlin/example/todo/desktop/Main.kt | 0 .../multiplatform-template/build.gradle.kts | 16 ++++++++++ .../desktop/build.gradle.kts | 17 +++++++--- .../src/{main => jvmMain}/kotlin/main.kt | 0 .../settings.gradle.kts | 16 ---------- 14 files changed, 104 insertions(+), 67 deletions(-) rename examples/imageviewer/desktop/src/{main => jvmMain}/kotlin/imageviewer/Main.kt (100%) mode change 100755 => 100644 rename examples/issues/desktop/src/{main => jvmMain}/kotlin/androidx/ui/examples/jetissues/Main.kt (100%) rename examples/todoapp/desktop/src/{main => jvmMain}/kotlin/example/todo/desktop/Main.kt (100%) mode change 100755 => 100644 rename templates/multiplatform-template/desktop/src/{main => jvmMain}/kotlin/main.kt (100%) diff --git a/examples/imageviewer/build.gradle.kts b/examples/imageviewer/build.gradle.kts index 602d7f27b0..42c2f3f832 100755 --- a/examples/imageviewer/build.gradle.kts +++ b/examples/imageviewer/build.gradle.kts @@ -1,3 +1,17 @@ +buildscript { + repositories { + google() + jcenter() + maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") + } + + dependencies { + classpath("org.jetbrains.compose:compose-gradle-plugin:0.1.0-dev97") + classpath("com.android.tools.build:gradle:4.0.1") + classpath(kotlin("gradle-plugin", version = "1.4.0")) + } +} + allprojects { repositories { mavenLocal() diff --git a/examples/imageviewer/desktop/build.gradle.kts b/examples/imageviewer/desktop/build.gradle.kts index 981c3132df..9d1ad462b4 100755 --- a/examples/imageviewer/desktop/build.gradle.kts +++ b/examples/imageviewer/desktop/build.gradle.kts @@ -1,15 +1,24 @@ import org.jetbrains.compose.compose plugins { - kotlin("jvm") + kotlin("multiplatform") id("org.jetbrains.compose") java application } -dependencies { - implementation(compose.desktop.all) - implementation(project(":common")) +kotlin { + jvm { + withJava() + } + sourceSets { + named("jvmMain") { + dependencies { + implementation(compose.desktop.all) + implementation(project(":common")) + } + } + } } application { diff --git a/examples/imageviewer/desktop/src/main/kotlin/imageviewer/Main.kt b/examples/imageviewer/desktop/src/jvmMain/kotlin/imageviewer/Main.kt old mode 100755 new mode 100644 similarity index 100% rename from examples/imageviewer/desktop/src/main/kotlin/imageviewer/Main.kt rename to examples/imageviewer/desktop/src/jvmMain/kotlin/imageviewer/Main.kt diff --git a/examples/imageviewer/settings.gradle.kts b/examples/imageviewer/settings.gradle.kts index aaede1ffa0..9a0d554e9b 100755 --- a/examples/imageviewer/settings.gradle.kts +++ b/examples/imageviewer/settings.gradle.kts @@ -1,15 +1 @@ -buildscript { - repositories { - google() - jcenter() - maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") - } - - dependencies { - classpath("org.jetbrains.compose:compose-gradle-plugin:0.1.0-dev97") - classpath("com.android.tools.build:gradle:4.0.1") - classpath(kotlin("gradle-plugin", version = "1.4.0")) - } -} - include(":common", ":android", ":desktop") diff --git a/examples/issues/build.gradle.kts b/examples/issues/build.gradle.kts index 602d7f27b0..42c2f3f832 100644 --- a/examples/issues/build.gradle.kts +++ b/examples/issues/build.gradle.kts @@ -1,3 +1,17 @@ +buildscript { + repositories { + google() + jcenter() + maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") + } + + dependencies { + classpath("org.jetbrains.compose:compose-gradle-plugin:0.1.0-dev97") + classpath("com.android.tools.build:gradle:4.0.1") + classpath(kotlin("gradle-plugin", version = "1.4.0")) + } +} + allprojects { repositories { mavenLocal() diff --git a/examples/issues/desktop/build.gradle.kts b/examples/issues/desktop/build.gradle.kts index be3c5edc90..7c2f7489c3 100644 --- a/examples/issues/desktop/build.gradle.kts +++ b/examples/issues/desktop/build.gradle.kts @@ -1,15 +1,24 @@ import org.jetbrains.compose.compose plugins { - kotlin("jvm") + kotlin("multiplatform") id("org.jetbrains.compose") java application } -dependencies { - implementation(compose.desktop.all) - implementation(project(":common")) +kotlin { + jvm { + withJava() + } + sourceSets { + named("jvmMain") { + dependencies { + implementation(compose.desktop.all) + implementation(project(":common")) + } + } + } } application { diff --git a/examples/issues/desktop/src/main/kotlin/androidx/ui/examples/jetissues/Main.kt b/examples/issues/desktop/src/jvmMain/kotlin/androidx/ui/examples/jetissues/Main.kt similarity index 100% rename from examples/issues/desktop/src/main/kotlin/androidx/ui/examples/jetissues/Main.kt rename to examples/issues/desktop/src/jvmMain/kotlin/androidx/ui/examples/jetissues/Main.kt diff --git a/examples/issues/settings.gradle.kts b/examples/issues/settings.gradle.kts index aaede1ffa0..9a0d554e9b 100644 --- a/examples/issues/settings.gradle.kts +++ b/examples/issues/settings.gradle.kts @@ -1,15 +1 @@ -buildscript { - repositories { - google() - jcenter() - maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") - } - - dependencies { - classpath("org.jetbrains.compose:compose-gradle-plugin:0.1.0-dev97") - classpath("com.android.tools.build:gradle:4.0.1") - classpath(kotlin("gradle-plugin", version = "1.4.0")) - } -} - include(":common", ":android", ":desktop") diff --git a/examples/todoapp/desktop/build.gradle.kts b/examples/todoapp/desktop/build.gradle.kts index 425c749221..2c851a5f12 100755 --- a/examples/todoapp/desktop/build.gradle.kts +++ b/examples/todoapp/desktop/build.gradle.kts @@ -1,22 +1,32 @@ import org.jetbrains.compose.compose plugins { - kotlin("jvm") + kotlin("multiplatform") id("org.jetbrains.compose") java application } -dependencies { - implementation(compose.desktop.all) - implementation(project(":common:utils")) - implementation(project(":common:database")) - implementation(project(":common:root")) - implementation(Deps.ArkIvanov.Decompose.decompose) - implementation(Deps.ArkIvanov.MVIKotlin.mvikotlin) - implementation(Deps.ArkIvanov.MVIKotlin.mvikotlinMain) - implementation(Deps.Badoo.Reaktive.reaktive) - implementation(Deps.Badoo.Reaktive.coroutinesInterop) +kotlin { + jvm { + withJava() + } + + sourceSets { + named("jvmMain") { + dependencies { + implementation(compose.desktop.all) + implementation(project(":common:utils")) + implementation(project(":common:database")) + implementation(project(":common:root")) + implementation(Deps.ArkIvanov.Decompose.decompose) + implementation(Deps.ArkIvanov.MVIKotlin.mvikotlin) + implementation(Deps.ArkIvanov.MVIKotlin.mvikotlinMain) + implementation(Deps.Badoo.Reaktive.reaktive) + implementation(Deps.Badoo.Reaktive.coroutinesInterop) + } + } + } } application { diff --git a/examples/todoapp/desktop/src/main/kotlin/example/todo/desktop/Main.kt b/examples/todoapp/desktop/src/jvmMain/kotlin/example/todo/desktop/Main.kt old mode 100755 new mode 100644 similarity index 100% rename from examples/todoapp/desktop/src/main/kotlin/example/todo/desktop/Main.kt rename to examples/todoapp/desktop/src/jvmMain/kotlin/example/todo/desktop/Main.kt diff --git a/templates/multiplatform-template/build.gradle.kts b/templates/multiplatform-template/build.gradle.kts index 44f0a96615..51718cc3dc 100644 --- a/templates/multiplatform-template/build.gradle.kts +++ b/templates/multiplatform-template/build.gradle.kts @@ -1,3 +1,19 @@ +buildscript { + val composeVersion = System.getenv("COMPOSE_TEMPLATE_COMPOSE_VERSION") ?: "0.1.0-dev97" + + repositories { + google() + jcenter() + maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") + } + + dependencies { + classpath("org.jetbrains.compose:compose-gradle-plugin:$composeVersion") + classpath("com.android.tools.build:gradle:4.0.1") + classpath(kotlin("gradle-plugin", version = "1.4.0")) + } +} + allprojects { repositories { google() diff --git a/templates/multiplatform-template/desktop/build.gradle.kts b/templates/multiplatform-template/desktop/build.gradle.kts index 89af4eb8d8..0db6ff4a32 100644 --- a/templates/multiplatform-template/desktop/build.gradle.kts +++ b/templates/multiplatform-template/desktop/build.gradle.kts @@ -1,15 +1,24 @@ import org.jetbrains.compose.compose plugins { - kotlin("jvm") + kotlin("multiplatform") id("org.jetbrains.compose") java application } -dependencies { - implementation(compose.desktop.all) - implementation(project(":common")) +kotlin { + jvm { + withJava() + } + sourceSets { + named("jvmMain") { + dependencies { + implementation(compose.desktop.all) + implementation(project(":common")) + } + } + } } application { diff --git a/templates/multiplatform-template/desktop/src/main/kotlin/main.kt b/templates/multiplatform-template/desktop/src/jvmMain/kotlin/main.kt similarity index 100% rename from templates/multiplatform-template/desktop/src/main/kotlin/main.kt rename to templates/multiplatform-template/desktop/src/jvmMain/kotlin/main.kt diff --git a/templates/multiplatform-template/settings.gradle.kts b/templates/multiplatform-template/settings.gradle.kts index 07c421fc8c..9a0d554e9b 100644 --- a/templates/multiplatform-template/settings.gradle.kts +++ b/templates/multiplatform-template/settings.gradle.kts @@ -1,17 +1 @@ -buildscript { - val composeVersion = System.getenv("COMPOSE_TEMPLATE_COMPOSE_VERSION") ?: "0.1.0-dev97" - - repositories { - google() - jcenter() - maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") - } - - dependencies { - classpath("org.jetbrains.compose:compose-gradle-plugin:$composeVersion") - classpath("com.android.tools.build:gradle:4.0.1") - classpath(kotlin("gradle-plugin", version = "1.4.0")) - } -} - include(":common", ":android", ":desktop") From 6c2457240bb1fb50ab5dbeecc738bc245768d3d6 Mon Sep 17 00:00:00 2001 From: Igor Demin Date: Wed, 28 Oct 2020 11:05:15 +0300 Subject: [PATCH 2/2] Multiplatform template in IDEA / Android Studio. Add comment about issue --- examples/imageviewer/desktop/build.gradle.kts | 2 +- examples/issues/desktop/build.gradle.kts | 2 +- examples/todoapp/desktop/build.gradle.kts | 2 +- templates/multiplatform-template/desktop/build.gradle.kts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/imageviewer/desktop/build.gradle.kts b/examples/imageviewer/desktop/build.gradle.kts index c54d966bac..1c0eb81892 100755 --- a/examples/imageviewer/desktop/build.gradle.kts +++ b/examples/imageviewer/desktop/build.gradle.kts @@ -1,7 +1,7 @@ import org.jetbrains.compose.compose plugins { - kotlin("multiplatform") + kotlin("multiplatform") // kotlin("jvm") doesn't work well in IDEA/AndroidStudio (https://github.com/JetBrains/compose-jb/issues/22) id("org.jetbrains.compose") java application diff --git a/examples/issues/desktop/build.gradle.kts b/examples/issues/desktop/build.gradle.kts index efe8934931..4a433dfef8 100644 --- a/examples/issues/desktop/build.gradle.kts +++ b/examples/issues/desktop/build.gradle.kts @@ -1,7 +1,7 @@ import org.jetbrains.compose.compose plugins { - kotlin("multiplatform") + kotlin("multiplatform") // kotlin("jvm") doesn't work well in IDEA/AndroidStudio (https://github.com/JetBrains/compose-jb/issues/22) id("org.jetbrains.compose") java application diff --git a/examples/todoapp/desktop/build.gradle.kts b/examples/todoapp/desktop/build.gradle.kts index 7075afcf1d..0ea31179d7 100755 --- a/examples/todoapp/desktop/build.gradle.kts +++ b/examples/todoapp/desktop/build.gradle.kts @@ -1,7 +1,7 @@ import org.jetbrains.compose.compose plugins { - kotlin("multiplatform") + kotlin("multiplatform") // kotlin("jvm") doesn't work well in IDEA/AndroidStudio (https://github.com/JetBrains/compose-jb/issues/22) id("org.jetbrains.compose") java application diff --git a/templates/multiplatform-template/desktop/build.gradle.kts b/templates/multiplatform-template/desktop/build.gradle.kts index 94c9483714..eaa9f9e584 100644 --- a/templates/multiplatform-template/desktop/build.gradle.kts +++ b/templates/multiplatform-template/desktop/build.gradle.kts @@ -1,7 +1,7 @@ import org.jetbrains.compose.compose plugins { - kotlin("multiplatform") + kotlin("multiplatform") // kotlin("jvm") doesn't work well in IDEA/AndroidStudio (https://github.com/JetBrains/compose-jb/issues/22) id("org.jetbrains.compose") java application