Skip to content

Commit

Permalink
Add some dependencies and versions of "androidx" and "org.jetbrains.a…
Browse files Browse the repository at this point in the history
…ndroidx" to "common-gradle-dependencies"
  • Loading branch information
ShreckYe committed Oct 18, 2024
1 parent badddff commit b89806f
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 11 deletions.
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/VersionsAndDependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ val alignedPluginVersion = "0.6.0-SNAPSHOT"

// "x.y.z" indicates the version of the way of organizing the code,
// and the date indicates the version when the dependency versions are updated.
val commonGradleDependenciesVersion = "0.7.2-20241016-SNAPSHOT"
val commonGradleDependenciesVersion = "0.8.0-20241016-SNAPSHOT"

// This is the source dependency version. There is another build source dependency in "buildSrc/build.gradle.kts".
val pluginProjectSourceDependentStableCommonGradleDependenciesVersion = "0.7.2-20241016-SNAPSHOT".apply {
val pluginProjectSourceDependentStableCommonGradleDependenciesVersion = "0.8.0-20241016-SNAPSHOT".apply {
//require(!endsWith("SNAPSHOT")) // TODO
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import org.gradle.api.artifacts.dsl.DependencyHandler

// some but not all default dependencies
class CommonDependencies(val versions: CommonVersions = CommonVersions()) {
interface SubgroupWithNameInArtifact {
val groupPrefix: String
val subgroupName: String
val defaultVersion: String
fun module(module: String, version: String = defaultVersion) =
"$groupPrefix.$subgroupName:$subgroupName-$module:$version"
}

inner class KotlinCommon internal constructor() {
val defaultVersion = versions.kotlinCommon
fun module(module: String, version: String = defaultVersion) =
Expand Down Expand Up @@ -43,6 +51,8 @@ class CommonDependencies(val versions: CommonVersions = CommonVersions()) {
val kotlinCommon = KotlinCommon()

inner class Kotlinx internal constructor() {
// TODO can be refactored with `SubgroupWithNameInArtifact`

inner class Coroutines internal constructor() {
val defaultVersion = versions.kotlinxCoroutines
fun module(module: String, version: String = defaultVersion) =
Expand Down Expand Up @@ -94,6 +104,7 @@ class CommonDependencies(val versions: CommonVersions = CommonVersions()) {

// official libraries from JetBrains

// TODO can be refactored with `SubgroupWithNameInArtifact`
inner class Exposed internal constructor() {
val defaultVersion = versions.exposed
fun module(module: String, version: String = defaultVersion) =
Expand All @@ -105,6 +116,7 @@ class CommonDependencies(val versions: CommonVersions = CommonVersions()) {

val exposed = Exposed()

// TODO can be refactored with `SubgroupWithNameInArtifact`
inner class Ktor internal constructor() {
val defaultVersion = versions.ktor
fun module(module: String, version: String = defaultVersion) =
Expand All @@ -123,17 +135,79 @@ class CommonDependencies(val versions: CommonVersions = CommonVersions()) {

val ktor = Ktor()

inner class Androidx internal constructor() {
val defaultAndroidxVersions = versions.androidx
fun activityCompose(version: String = defaultAndroidxVersions.activityCompose) =
"androidx.activity:activity-compose:$version"
// TODO consider refactoring other inner classes to this architecture too

class JetbrainsAndroidx(defaultVersions: CommonVersions.JetbrainsAndroidx) {
interface Subgroup : CommonDependencies.SubgroupWithNameInArtifact {
override val groupPrefix: String get() = "org.jetbrains.androidx"
}

class Lifecycle(override val defaultVersion: String) : Subgroup {
override val subgroupName: String get() = "lifecycle"

fun viewmodel(version: String = defaultVersion) =
module("viewmodel", version)

fun viewmodelCompose(version: String = defaultVersion) =
module("viewmodel-compose", version)
}

val lifecycle = Lifecycle(defaultVersions.lifecycle)

class Navigation(override val defaultVersion: String) : Subgroup {
override val subgroupName: String get() = "navigation"

fun runtime(version: String = defaultVersion) =
module("runtime", version)

fun compose(version: String = defaultVersion) =
module("compose", version)
}

val navigation = Navigation(defaultVersions.navigation)
}

val jetbrainsAndroidx = JetbrainsAndroidx(versions.jetBrainsAndroidx)

class Androidx(defaultVersions: CommonVersions.Androidx) {
companion object {
val `package` = "androidx"
}

interface Subgroup : SubgroupWithNameInArtifact {
override val groupPrefix get() = `package`
}

class Activity(override val defaultVersion: String) : Subgroup {
override val subgroupName get() = "activity"

fun compose(version: String = defaultVersion) =
module("compose", version)
}

val activity = Activity(defaultVersions.activity)

class Compose(defaultVersions: CommonVersions.Androidx.Compose) {
interface Subgroup : SubgroupWithNameInArtifact {
override val groupPrefix get() = "$`package`.compose"
}

class Ui(override val defaultVersion: String) : Subgroup {
override val subgroupName get() = "ui"
}

val ui = Ui(defaultVersions.common)
}

val compose = Compose(defaultVersions.compose)
}

val androidx = Androidx()
val androidx = Androidx(versions.androidx)


// others

// TODO can be refactored with `SubgroupWithNameInArtifact`
inner class Vertx internal constructor() {
val defaultVersion = versions.vertx

Expand Down Expand Up @@ -203,6 +277,7 @@ class CommonDependencies(val versions: CommonVersions = CommonVersions()) {

val orgJunit = OrgJunit()

// TODO can be refactored with `SubgroupWithNameInArtifact`
inner class Kotest internal constructor() {
val defaultVersion = versions.kotest
fun module(module: String, version: String = defaultVersion) =
Expand All @@ -217,6 +292,7 @@ class CommonDependencies(val versions: CommonVersions = CommonVersions()) {
fun postgreSql(version: String = versions.postgreSql) =
"org.postgresql:postgresql:$version"

// TODO can be refactored with `SubgroupWithNameInArtifact`
inner class Slf4j internal constructor() {
val defaultVersion = versions.slf4j
fun module(module: String, version: String = defaultVersion) =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.huanshankeji

class CommonVersions @JvmOverloads constructor(
class CommonVersions(
val kotlin: String = GeneratedVersions.kotlin,

val kotlinCommon: String = "0.4.0",
Expand All @@ -12,7 +12,6 @@ class CommonVersions @JvmOverloads constructor(
val kotlinxBenchmark: String = GeneratedVersions.kotlinxBenchmark,
val exposed: String = "0.53.0", // "0.54.0" deprecates the old DSL APIs as errors while we still depend on them.
val ktor: String = "2.3.12", // "3.0.0" uses Kotlin 2.0.20 too.
val composeMultiplatform: String = GeneratedVersions.composeMultiplatform, // this is usually only used in classpath dependencies
val androidx: Androidx = Androidx(),

val vertx: String = "4.5.10",
Expand All @@ -23,7 +22,26 @@ class CommonVersions @JvmOverloads constructor(
val slf4j: String = "1.7.36", // TODO: consider replacing with kotlin-logging (https://github.com/oshai/kotlin-logging)
val testContainers: String = "1.20.2"
) {
class Androidx(
val activityCompose: String = "1.9.2"
class JetbrainsAndroidx(
val composeMultiplatform: String = GeneratedVersions.composeMultiplatform, // this is usually only used in classpath dependencies
val lifecycle: String = "2.8.3",
val navigation: String = "2.8.0-alpha10",
)

val jetBrainsAndroidx = JetbrainsAndroidx()

val composeMultiplatform get() = jetBrainsAndroidx.composeMultiplatform

// https://developer.android.com/jetpack/androidx/versions
class Androidx(
val activity: String = "1.9.3",
val compose: Compose = Compose()
) {
class Compose(
val compiler: String = "1.5.15",
val common: String = "1.7.4", // for "animation", "foundation", "material","runtime", and "ui"
val material3: String = "1.3.0",
val material3Adaptive: String = "1.0.0"
)
}
}

0 comments on commit b89806f

Please sign in to comment.