From 896028d0bbabbb48bd9ca8c5dadb53f05706cf69 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 11 Nov 2024 16:49:11 +0600 Subject: [PATCH] migrate onto new templates-oriented in gradle model --- .../{{.module_name.lowercase()}}/build.gradle | 2 +- .../{{.module_name.lowercase()}}/build.gradle | 2 +- .../{{.module_name.lowercase()}}/build.gradle | 2 +- .../{{.module_name.lowercase()}}/build.gradle | 2 +- extensions.gradle | 49 +++++++++++-------- .../templates/defaultAndroidSettings.gradle | 0 .../templates/mppAndroidProject.gradle | 2 +- .../templates/mppJavaProject.gradle | 0 .../templates/mppJsProject.gradle | 0 .../mppProjectWithSerialization.gradle | 2 +- lib/build.gradle | 2 +- 11 files changed, 35 insertions(+), 28 deletions(-) rename defaultAndroidSettings.gradle => gradle/templates/defaultAndroidSettings.gradle (100%) rename mppAndroidProject.gradle => gradle/templates/mppAndroidProject.gradle (94%) rename mppJavaProject.gradle => gradle/templates/mppJavaProject.gradle (100%) rename mppJsProject.gradle => gradle/templates/mppJsProject.gradle (100%) rename mppProjectWithSerialization.gradle => gradle/templates/mppProjectWithSerialization.gradle (96%) diff --git a/.templates/mpp_android_module/{{.module_name.lowercase()}}/build.gradle b/.templates/mpp_android_module/{{.module_name.lowercase()}}/build.gradle index 2170ae4..a8912c9 100644 --- a/.templates/mpp_android_module/{{.module_name.lowercase()}}/build.gradle +++ b/.templates/mpp_android_module/{{.module_name.lowercase()}}/build.gradle @@ -4,5 +4,5 @@ plugins { id "com.android.library" } -apply from: "$mppAndroidProjectPresetPath" +apply from: "$mppAndroidProject" diff --git a/.templates/mpp_java_module/{{.module_name.lowercase()}}/build.gradle b/.templates/mpp_java_module/{{.module_name.lowercase()}}/build.gradle index 61d425e..99745a2 100644 --- a/.templates/mpp_java_module/{{.module_name.lowercase()}}/build.gradle +++ b/.templates/mpp_java_module/{{.module_name.lowercase()}}/build.gradle @@ -3,5 +3,5 @@ plugins { id "org.jetbrains.kotlin.plugin.serialization" } -apply from: "$mppJavaProjectPresetPath" +apply from: "$mppJavaProject" diff --git a/.templates/mpp_js_module/{{.module_name.lowercase()}}/build.gradle b/.templates/mpp_js_module/{{.module_name.lowercase()}}/build.gradle index 9676b5a..1277a1b 100644 --- a/.templates/mpp_js_module/{{.module_name.lowercase()}}/build.gradle +++ b/.templates/mpp_js_module/{{.module_name.lowercase()}}/build.gradle @@ -3,5 +3,5 @@ plugins { id "org.jetbrains.kotlin.plugin.serialization" } -apply from: "$mppJsProjectPresetPath" +apply from: "$mppJsProject" diff --git a/.templates/mpp_module/{{.module_name.lowercase()}}/build.gradle b/.templates/mpp_module/{{.module_name.lowercase()}}/build.gradle index 8a22926..37cad24 100644 --- a/.templates/mpp_module/{{.module_name.lowercase()}}/build.gradle +++ b/.templates/mpp_module/{{.module_name.lowercase()}}/build.gradle @@ -4,5 +4,5 @@ plugins { id "com.android.library" } -apply from: "$mppProjectWithSerializationPresetPath" +apply from: "$mppProjectWithSerialization" diff --git a/extensions.gradle b/extensions.gradle index 2e89947..2b5e461 100644 --- a/extensions.gradle +++ b/extensions.gradle @@ -1,25 +1,32 @@ -allprojects { - ext { - projectByName = { String name -> - for (subproject in rootProject.subprojects) { - if (subproject.name == name) { - return subproject - } - } - return null - } +File templatesFolder = new File("$rootProject.projectDir.absolutePath${File.separatorChar}gradle${File.separatorChar}templates") - internalProject = { String name -> - projectByName(name) - } +Map properties = new HashMap() - mppProjectWithSerializationPresetPath = "${rootProject.projectDir.absolutePath}/mppProjectWithSerialization.gradle" - mppJavaProjectPresetPath = "${rootProject.projectDir.absolutePath}/mppJavaProject.gradle" - mppJsProjectPresetPath = "${rootProject.projectDir.absolutePath}/mppJsProject.gradle" - mppAndroidProjectPresetPath = "${rootProject.projectDir.absolutePath}/mppAndroidProject.gradle" - - defaultAndroidSettingsPresetPath = "${rootProject.projectDir.absolutePath}/defaultAndroidSettings.gradle" - - // publishGradlePath = "${rootProject.projectDir.absolutePath}/publish.gradle" +if (templatesFolder.exists() && templatesFolder.isDirectory()) { + templatesFolder.listFiles().each { + properties[it.name - ".gradle"] = it.absolutePath + } +} + +properties["projectByName"] = { name -> + for (subproject in rootProject.subprojects) { + if (subproject.name == name) { + return subproject + } + } + return null +} + +properties["internalProject"] = { name -> + projectByName("$name") +} + +allprojects { + ext { + releaseMode = (project.hasProperty('RELEASE_MODE') && project.property('RELEASE_MODE') == "true") || System.getenv('RELEASE_MODE') == "true" + + properties.forEach { k, v -> + it[k] = v + } } } diff --git a/defaultAndroidSettings.gradle b/gradle/templates/defaultAndroidSettings.gradle similarity index 100% rename from defaultAndroidSettings.gradle rename to gradle/templates/defaultAndroidSettings.gradle diff --git a/mppAndroidProject.gradle b/gradle/templates/mppAndroidProject.gradle similarity index 94% rename from mppAndroidProject.gradle rename to gradle/templates/mppAndroidProject.gradle index ad15701..f541758 100644 --- a/mppAndroidProject.gradle +++ b/gradle/templates/mppAndroidProject.gradle @@ -36,4 +36,4 @@ kotlin { } } -apply from: "$defaultAndroidSettingsPresetPath" +apply from: "$defaultAndroidSettings" diff --git a/mppJavaProject.gradle b/gradle/templates/mppJavaProject.gradle similarity index 100% rename from mppJavaProject.gradle rename to gradle/templates/mppJavaProject.gradle diff --git a/mppJsProject.gradle b/gradle/templates/mppJsProject.gradle similarity index 100% rename from mppJsProject.gradle rename to gradle/templates/mppJsProject.gradle diff --git a/mppProjectWithSerialization.gradle b/gradle/templates/mppProjectWithSerialization.gradle similarity index 96% rename from mppProjectWithSerialization.gradle rename to gradle/templates/mppProjectWithSerialization.gradle index f8331a6..584c4f5 100644 --- a/mppProjectWithSerialization.gradle +++ b/gradle/templates/mppProjectWithSerialization.gradle @@ -62,4 +62,4 @@ java { targetCompatibility = JavaVersion.VERSION_17 } -apply from: "$defaultAndroidSettingsPresetPath" +apply from: "$defaultAndroidSettings" diff --git a/lib/build.gradle b/lib/build.gradle index 8a22926..37cad24 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -4,5 +4,5 @@ plugins { id "com.android.library" } -apply from: "$mppProjectWithSerializationPresetPath" +apply from: "$mppProjectWithSerialization"