From bb657809a7db4b40be563505c15a38d788b66094 Mon Sep 17 00:00:00 2001 From: Gijs van Veen Date: Fri, 7 Jun 2024 12:42:01 +0200 Subject: [PATCH] Moving embedding to plugin and got all Gradle building TODO: Weird android issue --- .idea/inspectionProfiles/ktlint.xml | 3 +- example/android/build.gradle.kts | 94 +++++++++++++++++++ example/build.gradle.kts | 15 +++ example/embedding/build.gradle.kts | 37 ++++++++ example/embedding/settings.gradle | 7 ++ .../src/main/kotlin/EmbeddingMode.kt | 25 +++++ .../src/main/kotlin/EmbeddingModeExtension.kt | 67 +++++++++++++ .../src/main/kotlin/EmbeddingPlugin.kt | 37 ++++++++ example/gradle.properties | 7 -- .../gradle/wrapper/gradle-wrapper.properties | 2 +- example/non_dependent_projects.properties | 1 - example/settings.gradle.kts | 57 ++--------- gradle/wrapper/gradle-wrapper.properties | 2 +- .../KalugaMultiplatformSubprojectExtension.kt | 16 ++-- .../kotlin/extensions/KalugaRootExtension.kt | 6 ++ libs.versions.toml | 2 +- 16 files changed, 309 insertions(+), 69 deletions(-) create mode 100644 example/embedding/build.gradle.kts create mode 100644 example/embedding/settings.gradle create mode 100644 example/embedding/src/main/kotlin/EmbeddingMode.kt create mode 100644 example/embedding/src/main/kotlin/EmbeddingModeExtension.kt create mode 100644 example/embedding/src/main/kotlin/EmbeddingPlugin.kt delete mode 100644 example/non_dependent_projects.properties diff --git a/.idea/inspectionProfiles/ktlint.xml b/.idea/inspectionProfiles/ktlint.xml index 7d04a74be..519da9b59 100644 --- a/.idea/inspectionProfiles/ktlint.xml +++ b/.idea/inspectionProfiles/ktlint.xml @@ -1,7 +1,8 @@ - + \ No newline at end of file diff --git a/example/android/build.gradle.kts b/example/android/build.gradle.kts index deb5baf66..cbbfe11b9 100644 --- a/example/android/build.gradle.kts +++ b/example/android/build.gradle.kts @@ -1,6 +1,100 @@ +import com.splendo.kaluga.plugin.helpers.gitBranch + plugins { id("com.android.application") + id(libs.plugins.kotlin.android.get().pluginId) + id(libs.plugins.compose.get().pluginId) + alias(libs.plugins.kotlin.serialization) } group = "com.splendo.kaluga" +version = "${libs.versions.kaluga.get()}${gitBranch.kalugaBranchPostfix}" + +android { + namespace = "com.splendo.kaluga.example" + compileSdk = libs.versions.androidCompileSdk.get().toInt() + buildToolsVersion = libs.versions.androidBuildTools.get() + defaultConfig { + applicationId = "com.splendo.kaluga.example" + minSdk = libs.versions.androidMinSdk.get().toInt() + targetSdk = libs.versions.androidCompileSdk.get().toInt() + versionCode = 1 + versionName = "1.0" + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + compileOptions { + sourceCompatibility = JavaVersion.toVersion(libs.versions.java.get()) + targetCompatibility = JavaVersion.toVersion(libs.versions.java.get()) + } + + signingConfigs { + get("debug").apply { + keyAlias = "key0" + keyPassword = "nckI1UYofHIMkOnXpmZJVA" + storeFile = file("../keystore/debug.keystore") + storePassword = "nckI1UYofHIMkOnXpmZJVA" + } + } + + kotlinOptions { + jvmTarget = libs.versions.java.get() + } + + buildTypes { + debug { + signingConfig = signingConfigs["debug"] + } + release { + isMinifyEnabled = false + proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") + } + } + + packaging { + resources.excludes.addAll( + listOf( + "META-INF/kotlinx-coroutines-core.kotlin_module", + "META-INF/shared_debug.kotlin_module", + "META-INF/kotlinx-serialization-runtime.kotlin_module" + ) + ) + } + + buildFeatures { + dataBinding { + enable = true + } + } +} + +dependencies { + implementation("com.splendo.kaluga:architecture-compose:$version") + implementation("com.splendo.kaluga:keyboard-compose:$version") + implementation("com.splendo.kaluga:resources-compose:$version") + implementation("com.splendo.kaluga:resources-databinding:$version") + implementation(project(":shared")) + + implementation(libs.androidx.compose.ui) + implementation(libs.androidx.compose.ui.tooling) + implementation(libs.androidx.compose.ui.tooling.preview) + implementation(libs.androidx.compose.foundation) + implementation(libs.androidx.compose.material) + implementation(libs.androidx.activity.compose) + implementation(libs.androidx.navigation.compose) + + implementation(libs.androidx.fragment) + implementation(libs.androidx.fragment.ktx) + implementation(libs.androidx.constraintlayout) + implementation(libs.androidx.lifecycle.service) + + implementation(libs.android.play.services.location) + implementation(libs.android.material) + implementation(libs.accompanist.themeadaptermaterial) + + implementation(libs.kotlinx.serialization.core) + implementation(libs.kotlinx.serialization.json) + + implementation(libs.koin.compose) +} diff --git a/example/build.gradle.kts b/example/build.gradle.kts index a1d92faba..7be4a8119 100644 --- a/example/build.gradle.kts +++ b/example/build.gradle.kts @@ -1,3 +1,18 @@ +import com.splendo.kaluga.example.plugin.EmbeddingMode + plugins { + id("com.splendo.kaluga.example.plugin") id("com.splendo.kaluga.plugin") } + +kaluga { + when (val embeddingMode = embedding.embeddingMode) { + is EmbeddingMode.MavenLocal -> { + includeMavenLocal = true + } + is EmbeddingMode.MavenRepo -> { + additionalMavenRepos.add(embeddingMode.repoUrl) + } + else -> {} + } +} diff --git a/example/embedding/build.gradle.kts b/example/embedding/build.gradle.kts new file mode 100644 index 000000000..6e130ded6 --- /dev/null +++ b/example/embedding/build.gradle.kts @@ -0,0 +1,37 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + `java-gradle-plugin` + `kotlin-dsl` + `kotlin-dsl-precompiled-script-plugins` + `version-catalog` + `maven-publish` + alias(libs.plugins.kotlinter) +} + +repositories { + gradlePluginPortal() // To use 'maven-publish' and 'signing' plugins in our own plugin + google() + mavenCentral() +} + +gradlePlugin { + plugins.register("com.splendo.kaluga.example.plugin") { + id = "com.splendo.kaluga.example.plugin" + implementationClass = "com.splendo.kaluga.example.plugin.EmbeddingPlugin" + } + plugins.register("com.splendo.kaluga.example.setting.plugin") { + id = "com.splendo.kaluga.example.settings.plugin" + implementationClass = "com.splendo.kaluga.example.plugin.EmbeddingSettingsPlugin" + } +} + +kotlin { + jvmToolchain(libs.versions.java.get().toInt()) +} + +val compileKotlin: KotlinCompile by tasks + +compileKotlin.kotlinOptions { + languageVersion = "2.0" +} \ No newline at end of file diff --git a/example/embedding/settings.gradle b/example/embedding/settings.gradle new file mode 100644 index 000000000..2f7d3fdcf --- /dev/null +++ b/example/embedding/settings.gradle @@ -0,0 +1,7 @@ +dependencyResolutionManagement { + versionCatalogs { + create("libs") { + from(files("../../libs.versions.toml")) + } + } +} \ No newline at end of file diff --git a/example/embedding/src/main/kotlin/EmbeddingMode.kt b/example/embedding/src/main/kotlin/EmbeddingMode.kt new file mode 100644 index 000000000..1e9cce057 --- /dev/null +++ b/example/embedding/src/main/kotlin/EmbeddingMode.kt @@ -0,0 +1,25 @@ +/* + Copyright 2024 Splendo Consulting B.V. The Netherlands + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ + +package com.splendo.kaluga.example.plugin + +sealed class EmbeddingMode { + data object Composite : EmbeddingMode() + data object MavenLocal : EmbeddingMode() + data class MavenRepo(val repoUrl: String) : EmbeddingMode() + data object None : EmbeddingMode() +} diff --git a/example/embedding/src/main/kotlin/EmbeddingModeExtension.kt b/example/embedding/src/main/kotlin/EmbeddingModeExtension.kt new file mode 100644 index 000000000..4a5cca0f6 --- /dev/null +++ b/example/embedding/src/main/kotlin/EmbeddingModeExtension.kt @@ -0,0 +1,67 @@ +/* + Copyright 2024 Splendo Consulting B.V. The Netherlands + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ + +package com.splendo.kaluga.example.plugin + +import org.gradle.api.logging.Logger +import java.util.Properties +import javax.inject.Inject + +open class EmbeddingModeExtension @Inject constructor(private val properties: Properties, private val logger: Logger) { + + val embeddingMode = generateEmbeddingMode() + + private fun generateEmbeddingMode(): EmbeddingMode { + val providedEmbeddingMethod = if (System.getenv().containsKey("EXAMPLE_EMBEDDING_METHOD")) { + System.getenv()["EXAMPLE_EMBEDDING_METHOD"].also { + logger.lifecycle("System env EXAMPLE_EMBEDDING_METHOD set to ${System.getenv()["EXAMPLE_EMBEDDING_METHOD"]}, using $it") + }!! + } else { + val exampleEmbeddingMethodLocalProperties = properties["kaluga.exampleEmbeddingMethod"] as? String + (exampleEmbeddingMethodLocalProperties ?: "composite").also { + logger.lifecycle("local.properties read (kaluga.exampleEmbeddingMethod=$exampleEmbeddingMethodLocalProperties, using $it)") + } + } + + return if (providedEmbeddingMethod == "composite") { + EmbeddingMode.Composite + } else { + val exampleMavenRepo = if (System.getenv().containsKey("EXAMPLE_MAVEN_REPO")) { + System.getenv()["EXAMPLE_MAVEN_REPO"].also { + logger.lifecycle("System env EXAMPLE_MAVEN_REPO set to ${System.getenv()["EXAMPLE_MAVEN_REPO"]}, using $it") + }!! + } else { + val exampleMavenRepoLocalProperties: String? = + properties["kaluga.exampleMavenRepo"] as? String + exampleMavenRepoLocalProperties?.also { + logger.lifecycle("local.properties read (kaluga.exampleMavenRepo=$exampleMavenRepoLocalProperties, using $it)") + } + ?: "local".also { + logger.info("local.properties not found, using default value ($it)") + } + } + logger.lifecycle("Using repo: $exampleMavenRepo for resolving dependencies") + + when (exampleMavenRepo) { + "", "local" -> EmbeddingMode.MavenLocal + "none" -> EmbeddingMode.None + else -> + EmbeddingMode.MavenRepo(exampleMavenRepo) + } + } + } +} \ No newline at end of file diff --git a/example/embedding/src/main/kotlin/EmbeddingPlugin.kt b/example/embedding/src/main/kotlin/EmbeddingPlugin.kt new file mode 100644 index 000000000..7af7155c0 --- /dev/null +++ b/example/embedding/src/main/kotlin/EmbeddingPlugin.kt @@ -0,0 +1,37 @@ +package com.splendo.kaluga.example.plugin + +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.initialization.Settings +import org.gradle.api.logging.Logger +import org.gradle.api.logging.Logging +import org.gradle.api.plugins.ExtensionContainer +import org.gradle.kotlin.dsl.create +import java.io.File +import java.io.FileInputStream +import java.util.Properties + +abstract class BaseEmbeddingPlugin { + fun apply(container: ExtensionContainer, rootDir: File, logger: Logger) { + val props = Properties() + val file = File(rootDir, "/local.properties") + if (file.exists()) { + props.load(FileInputStream(file)) + } + container.create("embedding", EmbeddingModeExtension::class, props, logger) + } +} + +class EmbeddingPlugin : BaseEmbeddingPlugin(), Plugin { + + override fun apply(target: Project) = target.run { + apply(extensions, target.rootDir, target.logger) + } +} + +class EmbeddingSettingsPlugin : BaseEmbeddingPlugin(), Plugin { + + override fun apply(target: Settings) = target.run { + apply(extensions, target.rootDir, Logging.getLogger(Settings::class.java)) + } +} diff --git a/example/gradle.properties b/example/gradle.properties index d4208b208..587bcd91f 100644 --- a/example/gradle.properties +++ b/example/gradle.properties @@ -16,10 +16,3 @@ org.gradle.parallel=true kotlin.mpp.enableCInteropCommonization=true kotlin.native.ignoreIncorrectDependencies=true kotlin.mpp.import.enableKgpDependencyResolution=true - -# Kaluga -kaluga.androidGradlePluginVersion=8.4.0 -kaluga.kotlinVersion=2.0.0 -kaluga.googleServicesGradlePluginVersion=4.4.1 -kaluga.kotlinterGradlePluginVersion=4.3.0 -kaluga.atomicFuGradlePluginVersion=0.24.0 \ No newline at end of file diff --git a/example/gradle/wrapper/gradle-wrapper.properties b/example/gradle/wrapper/gradle-wrapper.properties index 27bf8e08d..042246b00 100644 --- a/example/gradle/wrapper/gradle-wrapper.properties +++ b/example/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Fri Nov 04 13:12:48 CET 2022 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/example/non_dependent_projects.properties b/example/non_dependent_projects.properties deleted file mode 100644 index 5cc7ae96f..000000000 --- a/example/non_dependent_projects.properties +++ /dev/null @@ -1 +0,0 @@ -projects=["shared"] \ No newline at end of file diff --git a/example/settings.gradle.kts b/example/settings.gradle.kts index a3e978be0..b721251db 100644 --- a/example/settings.gradle.kts +++ b/example/settings.gradle.kts @@ -1,3 +1,4 @@ +import com.splendo.kaluga.example.plugin.EmbeddingMode import java.io.File import java.io.FileInputStream import java.util.Properties @@ -10,28 +11,11 @@ pluginManagement { } includeBuild("../kaluga-library-components") + includeBuild("./embedding") } -val props = Properties() -val file = File("$rootDir/local.properties") -if (file.exists()) { - props.load(FileInputStream(file)) -} - -val exampleEmbeddingMethod = if (System.getenv().containsKey("EXAMPLE_EMBEDDING_METHOD")) { - System.getenv()["EXAMPLE_EMBEDDING_METHOD"].also { - logger.lifecycle("System env EXAMPLE_EMBEDDING_METHOD set to ${System.getenv()["EXAMPLE_EMBEDDING_METHOD"]}, using $it") - }!! -} else { - val exampleEmbeddingMethodLocalProperties = props["kaluga.exampleEmbeddingMethod"] as? String - (exampleEmbeddingMethodLocalProperties ?: "composite").also { - logger.lifecycle("local.properties read (kaluga.exampleEmbeddingMethod=$exampleEmbeddingMethodLocalProperties, using $it)") - } -} - -val isCompositeBuild = when (exampleEmbeddingMethod) { - "composite" -> true - else -> false +plugins { + id("com.splendo.kaluga.example.settings.plugin") } dependencyResolutionManagement { @@ -40,41 +24,12 @@ dependencyResolutionManagement { from(files("../libs.versions.toml")) } } - repositories { - if (!isCompositeBuild) { - val exampleMavenRepo = if (System.getenv().containsKey("EXAMPLE_MAVEN_REPO")) { - System.getenv()["EXAMPLE_MAVEN_REPO"].also { - logger.lifecycle("System env EXAMPLE_MAVEN_REPO set to ${System.getenv()["EXAMPLE_MAVEN_REPO"]}, using $it") - }!! - } else { - val exampleMavenRepoLocalProperties: String? = - props["kaluga.exampleMavenRepo"] as? String - exampleMavenRepoLocalProperties?.also { - logger.lifecycle("local.properties read (kaluga.exampleMavenRepo=$exampleMavenRepoLocalProperties, using $it)") - } - ?: "local".also { - logger.info("local.properties not found, using default value ($it)") - } - } - logger.lifecycle("Using repo: $exampleMavenRepo for resolving dependencies") - - when (exampleMavenRepo) { - null, "", "local" -> mavenLocal() - "none" -> {/* noop */ - } - else -> - maven(exampleMavenRepo) - } - } - mavenCentral() - google() - } } rootProject.name = "Kaluga Example" -//include(":android") +include(":android") include(":shared") -if (isCompositeBuild) { +if (embedding.embeddingMode is EmbeddingMode.Composite) { includeBuild("../") } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index afa30cb1b..6f9e6eb69 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Mon Oct 10 09:58:47 CEST 2022 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/kaluga-library-components/src/main/kotlin/extensions/KalugaMultiplatformSubprojectExtension.kt b/kaluga-library-components/src/main/kotlin/extensions/KalugaMultiplatformSubprojectExtension.kt index 078c8390a..b6de09a6b 100644 --- a/kaluga-library-components/src/main/kotlin/extensions/KalugaMultiplatformSubprojectExtension.kt +++ b/kaluga-library-components/src/main/kotlin/extensions/KalugaMultiplatformSubprojectExtension.kt @@ -207,15 +207,19 @@ open class KalugaMultiplatformSubprojectExtension @Inject constructor( } } - sourceSets.getByName("appleMain").apply { - dependencies { - multiplatformDependencies.apple.mainDependencies.forEach { it.execute(this) } + if (multiplatformDependencies.apple.mainDependencies.isNotEmpty()) { + sourceSets.getByName("appleMain").apply { + dependencies { + multiplatformDependencies.apple.mainDependencies.forEach { it.execute(this) } + } } } - sourceSets.getByName("appleTest").apply { - dependencies { - multiplatformDependencies.apple.testDependencies.forEach { it.execute(this) } + if (multiplatformDependencies.apple.testDependencies.isNotEmpty()) { + sourceSets.getByName("appleTest").apply { + dependencies { + multiplatformDependencies.apple.testDependencies.forEach { it.execute(this) } + } } } diff --git a/kaluga-library-components/src/main/kotlin/extensions/KalugaRootExtension.kt b/kaluga-library-components/src/main/kotlin/extensions/KalugaRootExtension.kt index 8bcf555dd..f7330f111 100644 --- a/kaluga-library-components/src/main/kotlin/extensions/KalugaRootExtension.kt +++ b/kaluga-library-components/src/main/kotlin/extensions/KalugaRootExtension.kt @@ -23,6 +23,7 @@ import org.gradle.api.artifacts.VersionCatalog import org.gradle.api.model.ObjectFactory import org.gradle.kotlin.dsl.closureOf import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.maven import org.gradle.kotlin.dsl.repositories import org.owasp.dependencycheck.gradle.extension.AnalyzerExtension import org.owasp.dependencycheck.gradle.extension.DependencyCheckExtension @@ -41,6 +42,8 @@ open class KalugaRootExtension @Inject constructor( */ var includeMavenLocal = false + val additionalMavenRepos = mutableListOf() + override fun Project.beforeEvaluated() {} override fun Project.afterProjectEvaluated() { allprojects { @@ -48,6 +51,9 @@ open class KalugaRootExtension @Inject constructor( if (includeMavenLocal) { mavenLocal() } + additionalMavenRepos.forEach { + maven(it) + } google() mavenCentral() } diff --git a/libs.versions.toml b/libs.versions.toml index 4584aa2de..c82f55828 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -1,6 +1,6 @@ [versions] # kotlin version is included since it will affect building -androidGradle = "8.4.1" +androidGradle = "8.5.0-rc01" androidBuildTools = "34.0.0" androidCompileSdk = "34" androidMinSdk = "24"