Gradle Kotlin Versioning ❤ Composing Builds > BuildSrc 筆記

object Version {
const val kotlinxCoroutines = "1.5.0"
const val junit = "4.12"
const val truth = "1.1.3"
const val mockitoKotlin = "3.2.0"
const val robolectric = "4.5.1"
}
object Depends {
const val kotlinxCoroutinesCore = "org.jetbrains.kotlinx:kotlinx-coroutines-core:${Version.kotlinxCoroutines}"
const val kotlinxCoroutinesCoreTest = "org.jetbrains.kotlinx:kotlinx-coroutines-test:${Version.kotlinxCoroutines}"
const val junit = "junit:junit:${Version.junit}"
const val truth = "com.google.truth:truth:${Version.truth}"
const val mockitoKotlin = "org.mockito.kotlin:mockito-kotlin:${Version.mockitoKotlin}"
const val robolectric = "org.robolectric:robolectric:${Version.robolectric}"
}
+ package version.gradle

+ import org.gradle.api.Plugin
+ import org.gradle.api.Project

+ class VersionGradle : Plugin<Project> {
+ override fun apply(project: Project) {
+ }
+ }

object Version {
// ...
}

object Depends {
// ...
}
  rootProject.name = "aws-ktx"
+ includeBuild("version-gradle")
plugins {
`kotlin-dsl`
`java-gradle-plugin`
}

repositories {
mavenCentral()
}

gradlePlugin {
plugins {
create("version.gradle") {
id = "version.gradle"
implementationClass = "version.gradle.VersionGradle"
}
}
}
buildscript {
// ...
}
+ plugins {
+ id("version.gradle")
+ }
+ import version.gradle.*  // ...  dependencies {
// ...
testImplementation(Depends.junit)
testImplementation(Depends.truth)
  1. Ext 方案 (無法自動補全):buildscript { ext.xxxx = "" }
  2. build.gradle.kts + buildSrc 方案
  3. builld.gradle.kts + composing builds 方案 (效能較好,獨立 module 刷新)

References

--

--

--

https://github.com/yongjhih

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Mitigate Injection Attacks in NoSQL Databases

Pagination with ElasticSearch using NodeJS

Invite All Users to a Slack Channel

Channel Tools helps you to add all users in bulk to a Slack channel.

It is 2020 and You Haven’t Learn React.Js

Reusable Nesting Components in Reactive forms

How to Decrypt a ZIP File in Node.JS

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Andrew Chen

Andrew Chen

https://github.com/yongjhih

More from Medium

ACTIVITY LIFECYCLE IN KOTLIN

Kotlin Multiplatform library with Kotest and Gradle Version Catalog

MVP/MVC to Reactive Architectures for Jetpack Compose

Android MVC structure from https://www.codementor.io/@dragneelfps/implementing-mvc-pattern-in-android-with-kotlin-i9hi2r06c

Caffeine cache simplified in Kotlin