From b2213e3132fe3466fccc42d7cbecac41a2c339a8 Mon Sep 17 00:00:00 2001 From: Igor Demin Date: Thu, 16 Dec 2021 01:11:10 +0300 Subject: [PATCH] Fix Todo example Deps (#1607) task `gradlew jsBrowserDevelopmentRun` didn't work --- examples/todoapp/buildSrc/build.gradle.kts | 8 +++-- .../buildSrc/buildSrc/src/main/kotlin/Deps.kt | 29 +++++++++++-------- examples/todoapp/buildSrc/gradle.properties | 1 + .../src/main/kotlin/android-setup.gradle.kts | 2 ++ .../multiplatform-compose-setup.gradle.kts | 2 ++ .../kotlin/multiplatform-setup.gradle.kts | 12 ++++---- examples/todoapp/gradle.properties | 3 ++ 7 files changed, 37 insertions(+), 20 deletions(-) diff --git a/examples/todoapp/buildSrc/build.gradle.kts b/examples/todoapp/buildSrc/build.gradle.kts index bb48132e6a..6e5eb3d3c5 100644 --- a/examples/todoapp/buildSrc/build.gradle.kts +++ b/examples/todoapp/buildSrc/build.gradle.kts @@ -2,6 +2,8 @@ plugins { `kotlin-dsl` } +initDeps(project) + repositories { mavenLocal() google() @@ -10,8 +12,8 @@ repositories { } dependencies { - implementation(Deps.JetBrains.Compose(project).gradlePlugin) - implementation(Deps.JetBrains.Kotlin(project).gradlePlugin) + implementation(Deps.JetBrains.Compose.gradlePlugin) + implementation(Deps.JetBrains.Kotlin.gradlePlugin) implementation(Deps.Android.Tools.Build.gradlePlugin) implementation(Deps.Squareup.SQLDelight.gradlePlugin) } @@ -19,4 +21,4 @@ dependencies { kotlin { // Add Deps to compilation, so it will become available in main project sourceSets.getByName("main").kotlin.srcDir("buildSrc/src/main/kotlin") -} +} \ No newline at end of file diff --git a/examples/todoapp/buildSrc/buildSrc/src/main/kotlin/Deps.kt b/examples/todoapp/buildSrc/buildSrc/src/main/kotlin/Deps.kt index 3ba8272955..22fb775829 100644 --- a/examples/todoapp/buildSrc/buildSrc/src/main/kotlin/Deps.kt +++ b/examples/todoapp/buildSrc/buildSrc/src/main/kotlin/Deps.kt @@ -1,23 +1,28 @@ - -// We store Kotlin and Compose versions in gradle.properties to +// We store Kotlin and Compose versions in gradle.properties to // be able to override them on CI. // You probably won't need this, so you can get rid of `project` in this file. import org.gradle.api.Project +lateinit var properties: Map + +fun initDeps(project: Project) { + properties = project.properties +} + object Deps { object JetBrains { - class Kotlin(private val project: Project) { - private val VERSION = project.properties["kotlin.version"] - val gradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$VERSION" - val testCommon = "org.jetbrains.kotlin:kotlin-test-common:$VERSION" - val testJunit = "org.jetbrains.kotlin:kotlin-test-junit:$VERSION" - val testJs = "org.jetbrains.kotlin:kotlin-test-js:$VERSION" - val testAnnotationsCommon = "org.jetbrains.kotlin:kotlin-test-annotations-common:$VERSION" + object Kotlin { + private val VERSION get() = properties["kotlin.version"] + val gradlePlugin get() = "org.jetbrains.kotlin:kotlin-gradle-plugin:$VERSION" + val testCommon get() = "org.jetbrains.kotlin:kotlin-test-common:$VERSION" + val testJunit get() = "org.jetbrains.kotlin:kotlin-test-junit:$VERSION" + val testJs get() = "org.jetbrains.kotlin:kotlin-test-js:$VERSION" + val testAnnotationsCommon get() = "org.jetbrains.kotlin:kotlin-test-annotations-common:$VERSION" } - class Compose(private val project: Project) { - private val VERSION = project.properties["compose.version"] - val gradlePlugin = "org.jetbrains.compose:compose-gradle-plugin:$VERSION" + object Compose { + private val VERSION get() = properties["compose.version"] + val gradlePlugin get() = "org.jetbrains.compose:compose-gradle-plugin:$VERSION" } } diff --git a/examples/todoapp/buildSrc/gradle.properties b/examples/todoapp/buildSrc/gradle.properties index 09a8915b34..09a6ac3d11 100755 --- a/examples/todoapp/buildSrc/gradle.properties +++ b/examples/todoapp/buildSrc/gradle.properties @@ -1,2 +1,3 @@ +# TODO can we get rid of duplication with root gradle.properties? kotlin.version=1.6.10 compose.version=1.0.1-rc2 diff --git a/examples/todoapp/buildSrc/src/main/kotlin/android-setup.gradle.kts b/examples/todoapp/buildSrc/src/main/kotlin/android-setup.gradle.kts index 3cf1ab98d5..095b16947b 100644 --- a/examples/todoapp/buildSrc/src/main/kotlin/android-setup.gradle.kts +++ b/examples/todoapp/buildSrc/src/main/kotlin/android-setup.gradle.kts @@ -2,6 +2,8 @@ plugins { id("com.android.library") } +initDeps(project) + android { compileSdkVersion(31) diff --git a/examples/todoapp/buildSrc/src/main/kotlin/multiplatform-compose-setup.gradle.kts b/examples/todoapp/buildSrc/src/main/kotlin/multiplatform-compose-setup.gradle.kts index 7d007fdfd3..94b9f5d4aa 100644 --- a/examples/todoapp/buildSrc/src/main/kotlin/multiplatform-compose-setup.gradle.kts +++ b/examples/todoapp/buildSrc/src/main/kotlin/multiplatform-compose-setup.gradle.kts @@ -6,6 +6,8 @@ plugins { id("org.jetbrains.compose") } +initDeps(project) + kotlin { jvm("desktop") android() diff --git a/examples/todoapp/buildSrc/src/main/kotlin/multiplatform-setup.gradle.kts b/examples/todoapp/buildSrc/src/main/kotlin/multiplatform-setup.gradle.kts index f7bb6d5ab6..870dfbf62b 100644 --- a/examples/todoapp/buildSrc/src/main/kotlin/multiplatform-setup.gradle.kts +++ b/examples/todoapp/buildSrc/src/main/kotlin/multiplatform-setup.gradle.kts @@ -3,6 +3,8 @@ plugins { id("kotlin-multiplatform") } +initDeps(project) + kotlin { jvm("desktop") android() @@ -15,24 +17,24 @@ kotlin { sourceSets { named("commonTest") { dependencies { - implementation(Deps.JetBrains.Kotlin(project).testCommon) - implementation(Deps.JetBrains.Kotlin(project).testAnnotationsCommon) + implementation(Deps.JetBrains.Kotlin.testCommon) + implementation(Deps.JetBrains.Kotlin.testAnnotationsCommon) } } named("androidTest") { dependencies { - implementation(Deps.JetBrains.Kotlin(project).testJunit) + implementation(Deps.JetBrains.Kotlin.testJunit) } } named("desktopTest") { dependencies { - implementation(Deps.JetBrains.Kotlin(project).testJunit) + implementation(Deps.JetBrains.Kotlin.testJunit) } } named("jsTest") { dependencies { - implementation(Deps.JetBrains.Kotlin(project).testJs) + implementation(Deps.JetBrains.Kotlin.testJs) } } } diff --git a/examples/todoapp/gradle.properties b/examples/todoapp/gradle.properties index 21b172fe86..83e23bb5b2 100755 --- a/examples/todoapp/gradle.properties +++ b/examples/todoapp/gradle.properties @@ -22,3 +22,6 @@ kotlin.code.style=official org.gradle.parallel=true org.gradle.caching=true kotlin.native.disableCompilerDaemon=true + +kotlin.version=1.6.10 +compose.version=1.0.1-rc2 \ No newline at end of file