In the process of componentization, we are faced with many scenarios such as reuse and switching. For THE DSL file in componentization, we can also try to put its components out for better reuse and management.
Componentize the DSL file with buildSrc +. Buildscript
1.1 buildSrc
BuildSrc is a way to use the Kotlin DSL + Kotlin language to act as ext in Groovy. Android Studio can automatically form a dependency document in the project root, which we can then use to manage version numbers. Dependencies and a way to provide some kotlin properties to help us develop better interactions with the writing language.
1.1.1 create buildSrc
- Create a buildSrc folder at the project root (note that the name must be the same)
- Create a build.gradle. KTS file and a SRC /kotlin file under the file
- build.gradle.kts
buildscript {
repositories {
jcenter()
}
}
repositories {
jcenter()
}
plugins {
`kotlin-dsl`
}
kotlinDslPluginOptions {
experimentalWarning.set(false)}Copy the code
1.2 create buildscript
Gradle for different responsibilities
-
use
Components in the host
apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply from: rootProject.file(".buildscript/base-dependencies.gradle") apply from: rootProject.file(".buildscript/config-keystore.gradle") android { defaultConfig { applicationId "com.realu.dating" } } dependencies { if (! isApplication.toBoolean()) { implementation project(path: ':realu-live') } }Copy the code
Among other components
apply from: rootProject.file(".buildscript/base-component.gradle")
Copy the code
conclusion
In this way, the dependencies can be better managed by the project dependencies, and the DSLS for different responsibilities can be introduced to achieve the desired effect, which can be managed jointly and personalized