Don Phillips
09/10/2020, 7:08 PMDon Phillips
09/10/2020, 7:34 PMDon Phillips
09/10/2020, 7:43 PMSkaldebane
09/10/2020, 8:11 PMDon Phillips
09/10/2020, 8:41 PMpluginManagement {
val kotlinVersion = "1.4.0"
val androidGradleVersion = "4.0.1"
val realmVersion = "6.1.0"
val newRelicVersion = "5.27.0"
val firebaseCrashlyticsVersion = "2.2.0"
val googleServicesVersion = "4.3.3"
val hiltVersion = "2.28.3-alpha"
repositories {
gradlePluginPortal()
google()
}
@Suppress("UnstableApiUsage") plugins {
// In the event we ever get a plugin that has a plugin marker artifact, we can set the
// version of that plugin used across all modules here with an entry like this:
// id("id.of.plugin") version "X.Y.Z"
}
data class PluginArtifactMapping(
val pluginIds: List<String>,
private val artifact: String,
private val version: String
) {
val pluginDependencyCoordinates: String
get() = "$artifact:$version"
}
resolutionStrategy {
val plugins = listOf(
PluginArtifactMapping(
listOf("com.android.application", "com.android.library"),
"com.android.tools.build:gradle",
androidGradleVersion
), PluginArtifactMapping(
listOf("realm-android"), "io.realm:realm-gradle-plugin", realmVersion
), PluginArtifactMapping(
listOf("newrelic"),
"com.newrelic.agent.android:agent-gradle-plugin",
newRelicVersion
), PluginArtifactMapping(
listOf("com.google.gms.google-services"),
"com.google.gms:google-services",
googleServicesVersion
), PluginArtifactMapping(
listOf("com.google.firebase.crashlytics"),
"com.google.firebase:firebase-crashlytics-gradle",
firebaseCrashlyticsVersion
), PluginArtifactMapping(
listOf("dagger.hilt.android.plugin"),
"com.google.dagger:hilt-android-gradle-plugin",
hiltVersion
)
)
eachPlugin {
// Map the ID's of plugins using legacy way of registering with Gradle (meaning that
// these plugins do not have plugin marker artifacts) to the module that contains the
// plugin. This also has the effect of setting the version of these plugins, since the
// module version is specified here
plugins.forEach { payload ->
if (requested.id.id in payload.pluginIds) {
useModule(payload.pluginDependencyCoordinates)
return@forEach
}
}
// Set all Kotlin plugins to use the same version of Kotlin we want
if (requested.id.namespace?.startsWith("org.jetbrains.kotlin") == true) {
useVersion(kotlinVersion)
}
}
}
}
And in my modules' build.gradle.kts, I've got this
import com.albert.gradle.plugins.android.Deps
plugins {
id("com.albert.gradle.plugins.android.albert-android-library")
kotlin("kapt")
id("realm-android")
}
dependencies {
implementation(fileTree(mapOf("include" to listOf("*.jar"), "dir" to "libs")))
implementation(project(":network"))
implementation(project(":library_resources"))
implementation(project(":library_extensions"))
implementation(project(":utils"))
implementation(Deps.kotlin.stdlib.jdk8)
// Gson
implementation(Deps.google.gson)
// JodaTime
implementation(Deps.jodaTime)
// Realm Field Names
kapt(Deps.realmFieldNames)
}
And here's the Deps.kotlin object from the custom plugin:Don Phillips
09/10/2020, 8:41 PMobject Kotlin {
// TODO-gradle-refactor Can we pull this out somewhere and make it usable for plugins?
private const val kotlinVersion = "1.4.0"
val stdlib = Stdlib()
val test = Test
val kotlinx = Kotlinx
const val reflect = "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
class Stdlib(
private val name: String = "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
) : CharSequence by name {
val jdk7 = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
val jdk8 = "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
override fun toString(): String = name
}
object Test {
const val common = "org.jetbrains.kotlin:kotlin-test-common:$kotlinVersion"
const val js = "org.jetbrains.kotlin:kotlin-test-js:$kotlinVersion"
const val junit = "org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion"
const val annotationsCommon =
"org.jetbrains.kotlin:kotlin-test-annotations-common:$kotlinVersion"
}
object Kotlinx {
// Version number for dependencies from <https://github.com/Kotlin/kotlinx.coroutines>
private const val kotlinCoroutinesVersion = "1.3.9"
val test = Test
const val coroutinesAndroid =
"org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlinCoroutinesVersion"
object Test {
const val coroutines =
"org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlinCoroutinesVersion"
}
}
}
Alexey Belkov [JB]
09/11/2020, 9:03 AM