Skip to content

Commit

Permalink
Moving embedding to plugin and got all Gradle building
Browse files Browse the repository at this point in the history
TODO: Weird android issue
  • Loading branch information
Daeda88 committed Jun 7, 2024
1 parent ec2735d commit bb65780
Show file tree
Hide file tree
Showing 16 changed files with 309 additions and 69 deletions.
3 changes: 2 additions & 1 deletion .idea/inspectionProfiles/ktlint.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 94 additions & 0 deletions example/android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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)
}

15 changes: 15 additions & 0 deletions example/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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 -> {}
}
}
37 changes: 37 additions & 0 deletions example/embedding/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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"
}
7 changes: 7 additions & 0 deletions example/embedding/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../../libs.versions.toml"))
}
}
}
25 changes: 25 additions & 0 deletions example/embedding/src/main/kotlin/EmbeddingMode.kt
Original file line number Diff line number Diff line change
@@ -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()
}
67 changes: 67 additions & 0 deletions example/embedding/src/main/kotlin/EmbeddingModeExtension.kt
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
}
37 changes: 37 additions & 0 deletions example/embedding/src/main/kotlin/EmbeddingPlugin.kt
Original file line number Diff line number Diff line change
@@ -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<Project> {

override fun apply(target: Project) = target.run {
apply(extensions, target.rootDir, target.logger)
}
}

class EmbeddingSettingsPlugin : BaseEmbeddingPlugin(), Plugin<Settings> {

override fun apply(target: Settings) = target.run {
apply(extensions, target.rootDir, Logging.getLogger(Settings::class.java))
}
}
7 changes: 0 additions & 7 deletions example/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion example/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion example/non_dependent_projects.properties

This file was deleted.

Loading

0 comments on commit bb65780

Please sign in to comment.