-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
94fa514
commit af176bf
Showing
27 changed files
with
496 additions
and
255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.gradle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
plugins { | ||
`kotlin-dsl` | ||
} | ||
|
||
group = "dev.androidbroadcast.news.buildlogic" | ||
|
||
// Configure the build-logic plugins to target JDK 17 | ||
// This matches the JDK used to build the project, and is not related to what is running on device. | ||
java { | ||
sourceCompatibility = JavaVersion.VERSION_17 | ||
targetCompatibility = JavaVersion.VERSION_17 | ||
} | ||
|
||
kotlin { | ||
jvmToolchain { | ||
version = JavaVersion.VERSION_21 | ||
} | ||
|
||
compilerOptions { | ||
target { | ||
version = JavaVersion.VERSION_17 | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compileOnly(libs.gradlePlugins.android) | ||
compileOnly(libs.gradlePlugins.kotlin) | ||
} | ||
|
||
gradlePlugin { | ||
plugins { | ||
register("newsKmpPlugin") { | ||
id = "dev.androidbroadcast.news.kmpplugin" | ||
implementationClass = "dev.androidbroadcast.news.buildlogic.NewsKMPPlugin" | ||
} | ||
|
||
register("newsKmpPluginCompose") { | ||
id = "dev.androidbroadcast.news.kmpplugin.compose" | ||
implementationClass = "dev.androidbroadcast.news.buildlogic.NewsKMPComposePlugin" | ||
} | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
build-logic/convention/src/main/kotlin/dev/androidbroadcast/news/buildlogic/KMPSetups.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package dev.androidbroadcast.news.buildlogic | ||
|
||
import com.android.build.gradle.LibraryExtension | ||
import org.gradle.api.JavaVersion | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.dependencies | ||
import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode | ||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget | ||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension | ||
|
||
internal fun Project.setupKMPModule( | ||
kmpExt: KotlinMultiplatformExtension, | ||
androidLibraryExt: LibraryExtension, | ||
newsKMPExtension: NewsKMPExtension, | ||
withCompose: Boolean, | ||
) { | ||
kmpExt.apply { | ||
explicitApi = ExplicitApiMode.Strict | ||
|
||
androidTarget { | ||
compilerOptions { | ||
jvmTarget.set(JvmTarget.JVM_1_8) | ||
} | ||
} | ||
|
||
jvm() | ||
|
||
listOf( | ||
iosX64(), | ||
iosArm64(), | ||
iosSimulatorArm64() | ||
).forEach { iosTarget -> | ||
iosTarget.binaries.framework { | ||
baseName = this@setupKMPModule.displayName | ||
isStatic = true | ||
} | ||
} | ||
|
||
sourceSets.apply { | ||
commonMain.dependencies { | ||
api(versionCatalog.findLibrary("kotlinx-coroutines-core").get()) | ||
api(versionCatalog.findLibrary("kotlinx-immutable").get()) | ||
api(versionCatalog.findLibrary("kotlinx-datetime").get()) | ||
api(versionCatalog.findLibrary("koin-core").get()) | ||
} | ||
|
||
androidMain.dependencies { | ||
api(versionCatalog.findLibrary("androidx-core-ktx").get()) | ||
api(versionCatalog.findLibrary("kotlinx-coroutines-android").get()) | ||
api(versionCatalog.findLibrary("koin-android").get()) | ||
} | ||
|
||
jvmMain.dependencies { | ||
api(versionCatalog.findLibrary("kotlinx-coroutines-swing").get()) | ||
} | ||
} | ||
} | ||
|
||
androidLibraryExt.apply { | ||
namespace = newsKMPExtension.androidNamespace.get() | ||
compileSdk = | ||
versionCatalog | ||
.findVersion("androidSdk-compile") | ||
.get() | ||
.toString() | ||
.toInt() | ||
|
||
defaultConfig { | ||
minSdk = | ||
versionCatalog | ||
.findVersion("androidSdk-min") | ||
.get() | ||
.toString() | ||
.toInt() | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
} | ||
|
||
if (withCompose) { | ||
setupComposeMp(kmpExt, androidLibraryExt) | ||
} | ||
} | ||
|
||
private fun Project.setupComposeMp( | ||
kmpExt: KotlinMultiplatformExtension, | ||
androidLibraryExt: LibraryExtension, | ||
) { | ||
with(pluginManager) { | ||
apply("org.jetbrains.kotlin.plugin.compose") | ||
apply("org.jetbrains.compose") | ||
} | ||
|
||
androidLibraryExt.apply { | ||
buildFeatures.apply { | ||
compose = true | ||
} | ||
|
||
dependencies { | ||
add("debugImplementation", versionCatalog.findLibrary("compose-uiTooling").get()) | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...c/convention/src/main/kotlin/dev/androidbroadcast/news/buildlogic/NewsKMPComposePlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package dev.androidbroadcast.news.buildlogic | ||
|
||
import com.android.build.gradle.LibraryExtension | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.create | ||
import org.gradle.kotlin.dsl.getByType | ||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension | ||
|
||
class NewsKMPComposePlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
with(pluginManager) { | ||
apply("org.jetbrains.kotlin.multiplatform") | ||
apply("com.android.library") | ||
} | ||
|
||
val newsKMPExtension = extensions.create<NewsKMPExtension>("newsProject") | ||
val androidLibraryExt: LibraryExtension = extensions.getByType() | ||
val kmpExt: KotlinMultiplatformExtension = extensions.getByType() | ||
|
||
setupKMPModule( | ||
kmpExt, | ||
androidLibraryExt, | ||
newsKMPExtension, | ||
withCompose = true | ||
) | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...logic/convention/src/main/kotlin/dev/androidbroadcast/news/buildlogic/NewsKMPExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package dev.androidbroadcast.news.buildlogic | ||
|
||
import org.gradle.api.Project | ||
import org.gradle.api.provider.Property | ||
import org.gradle.kotlin.dsl.property | ||
|
||
open class NewsKMPExtension internal constructor(project: Project) { | ||
|
||
var androidNamespace: Property<String> = project.objects.property<String>().convention("") | ||
} |
29 changes: 29 additions & 0 deletions
29
build-logic/convention/src/main/kotlin/dev/androidbroadcast/news/buildlogic/NewsKMPPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package dev.androidbroadcast.news.buildlogic | ||
|
||
import com.android.build.gradle.LibraryExtension | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.configure | ||
import org.gradle.kotlin.dsl.create | ||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension | ||
|
||
class NewsKMPPlugin : Plugin<Project> { | ||
|
||
override fun apply(target: Project) { | ||
with(target) { | ||
with(pluginManager) { | ||
apply("org.jetbrains.kotlin.multiplatform") | ||
apply("com.android.library") | ||
} | ||
|
||
val newsKMPExtension = extensions.create<NewsKMPExtension>("newsProject") | ||
|
||
extensions.configure<LibraryExtension> { | ||
val androidLibraryExt: LibraryExtension = this | ||
extensions.configure<KotlinMultiplatformExtension> { | ||
setupKMPModule(this, androidLibraryExt, newsKMPExtension, withCompose = true) | ||
} | ||
} | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
build-logic/convention/src/main/kotlin/dev/androidbroadcast/news/buildlogic/Utils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package dev.androidbroadcast.news.buildlogic | ||
|
||
import org.gradle.api.Project | ||
import org.gradle.api.artifacts.VersionCatalog | ||
import org.gradle.api.artifacts.VersionCatalogsExtension | ||
import org.gradle.kotlin.dsl.getByType | ||
|
||
internal val Project.versionCatalog: VersionCatalog | ||
get() = extensions.getByType<VersionCatalogsExtension>().named("libs") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
@file:Suppress("UnstableApiUsage") | ||
|
||
dependencyResolutionManagement { | ||
repositories { | ||
google { | ||
content { | ||
includeGroupByRegex("com\\.android.*") | ||
includeGroupByRegex("com\\.google.*") | ||
includeGroupByRegex("androidx.*") | ||
} | ||
} | ||
gradlePluginPortal() | ||
mavenCentral() | ||
} | ||
|
||
versionCatalogs { | ||
create("libs") { | ||
from(files("../gradle/libs.versions.toml")) | ||
} | ||
} | ||
} | ||
|
||
rootProject.name = "build-logic" | ||
include(":convention") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,17 @@ | ||
@file:OptIn(ExperimentalKotlinGradlePluginApi::class) | ||
|
||
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi | ||
import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode | ||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget | ||
|
||
plugins { | ||
alias(libs.plugins.androidLibrary) | ||
alias(libs.plugins.kotlinMultiplatform) | ||
alias(libs.plugins.detekt) | ||
id("dev.androidbroadcast.news.kmpplugin") | ||
} | ||
|
||
kotlin { | ||
explicitApi = ExplicitApiMode.Strict | ||
|
||
androidTarget { | ||
compilerOptions { | ||
jvmTarget.set(JvmTarget.JVM_1_8) | ||
} | ||
} | ||
|
||
jvm() | ||
|
||
listOf( | ||
iosX64(), | ||
iosArm64(), | ||
iosSimulatorArm64() | ||
).forEach { iosTarget -> | ||
iosTarget.binaries.framework { | ||
baseName = "CoreCommon" | ||
isStatic = true | ||
} | ||
} | ||
newsProject { | ||
androidNamespace.set("dev.androidbroadcast.news.common") | ||
} | ||
|
||
kotlin { | ||
sourceSets { | ||
commonMain.dependencies { | ||
api(libs.kotlinx.coroutines.core) | ||
api(libs.kotlinx.immutable) | ||
api(libs.kotlinx.datetime) | ||
api(libs.coil.core) | ||
api(libs.koin.core) | ||
implementation(libs.coil.network.ktor) | ||
} | ||
|
||
androidMain.dependencies { | ||
implementation(libs.androidx.core.ktx) | ||
api(libs.kotlinx.coroutines.android) | ||
api(libs.koin.android) | ||
} | ||
|
||
jvmMain.dependencies { | ||
api(libs.kotlinx.coroutines.swing) | ||
} | ||
} | ||
} | ||
|
||
android { | ||
namespace = "dev.androidbroadcast.news.common" | ||
compileSdk = libs.versions.androidSdk.compile.get().toInt() | ||
|
||
defaultConfig { | ||
minSdk = libs.versions.androidSdk.min.get().toInt() | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 0 additions & 5 deletions
5
...ase/src/androidMain/kotlin/dev/androidbroadcast/news/database/NewsRoomDatabase.android.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,5 +32,3 @@ fun NewsDatabase( | |
.build() | ||
) | ||
} | ||
|
||
public expect fun instantiateNewsRoomDatabase(): NewsRoomDatabase |
3 changes: 3 additions & 0 deletions
3
...tabase/src/iosMain/kotlin/dev/androidbroadcast/news/database/NewsRoomDatabase.iosArm64.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package dev.androidbroadcast.news.database | ||
|
||
public expect fun instantiateNewsRoomDatabase(): NewsRoomDatabase |
5 changes: 0 additions & 5 deletions
5
core/database/src/jvmMain/kotlin/dev/androidbroadcast/news/database/NewsRoomDatabase.jvm.kt
This file was deleted.
Oops, something went wrong.
15 changes: 8 additions & 7 deletions
15
core/platform/src/androidMain/kotlin/dev/androidbroadcast/news/core/KoinModules.android.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,26 @@ | ||
package dev.androidbroadcast.news.core | ||
|
||
import android.app.Application | ||
import androidx.room.Room | ||
import androidx.room.RoomDatabase | ||
import dev.androidbroadcast.common.AndroidLogcatLogger | ||
import dev.androidbroadcast.common.Logger | ||
import dev.androidbroadcast.news.database.NewsRoomDatabase | ||
import org.koin.android.ext.koin.androidContext | ||
import org.koin.core.Koin | ||
import org.koin.core.module.Module | ||
import org.koin.dsl.module | ||
import org.koin.mp.KoinPlatform | ||
|
||
internal actual val targetKoinModule: Module = module { | ||
internal actual class TargetKoinDependencies { | ||
|
||
factory<RoomDatabase.Builder<NewsRoomDatabase>> { | ||
Room.databaseBuilder( | ||
context = androidContext(), | ||
actual fun newsRoomDatabaseBuilder(): RoomDatabase.Builder<NewsRoomDatabase> { | ||
return Room.databaseBuilder( | ||
context = KoinPlatform.getKoin().get<Application>(), | ||
klass = NewsRoomDatabase::class.java, | ||
name = "news" | ||
) | ||
} | ||
|
||
factory<Logger> { | ||
AndroidLogcatLogger() | ||
} | ||
actual fun logger(): Logger = AndroidLogcatLogger() | ||
} |
Oops, something went wrong.