Gradle 配置后续一致更新
当Gradle 下载慢时使用镜像下载快
distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-8.7-all.zip
国内网络下载比较慢可以使用阿里的镜像
maven(url = "https://maven.aliyun.com/repository/google")
maven(url = "https://maven.aliyun.com/repository/public")
maven(url = "https://maven.aliyun.com/repository/central")
maven(url = "https://maven.aliyun.com/repository/gradle-plugin")
当项目比较大依赖较多时可以使用 build来处理
gradle 使用kts 来写
pluginManagement {
includeBuild("build-logic")
}
创建build-logic 项目
settings.gradle.kts
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
rootProject.name = "build-logic"
include(":convention")
build.gradle.kts
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
`kotlin-dsl`
}
group = "top.chengdongqing.weui.buildlogic"
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
}
}
dependencies {
compileOnly(libs.android.gradle.plugin)
compileOnly(libs.android.tools.common)
compileOnly(libs.kotlin.gradle.plugin)
compileOnly(libs.room.gradle.plugin)
compileOnly(libs.ksp.gradle.plugin)
}
tasks {
validatePlugins {
enableStricterValidation = true
failOnWarning = true
}
}
gradlePlugin {
plugins {
// val prefix = "weui"
// register("androidComposeApplication") {
// id = "$prefix.android.compose.application"
// implementationClass = "AndroidComposeApplicationConventionPlugin"
// }
// register("androidComposeLibrary") {
// id = "$prefix.android.compose.library"
// implementationClass = "AndroidComposeLibraryConventionPlugin"
// }
// register("androidRoom") {
// id = "$prefix.android.room"
// implementationClass = "AndroidRoomConventionPlugin"
// }
register("androidComposeLibrary"){
id = "vic_demo"
implementationClass = "VicPlugin"
}
register("androidComposeApplication"){
id = "vic_app"
implementationClass = "VicAppPlugin"
}
}
}
class VicPlugin : Plugin<Project> {
override fun apply(target: Project) {
println("vic plugin")
with(target){
with(pluginManager) {
apply("com.android.library")
apply("org.jetbrains.kotlin.android")
//apply("androidx.room")
//apply("com.google.devtools.ksp")
}
println("vic plugin 22")
// extensions.configure<RoomExtension> {
// // schemaDirectory("$projectDir/schemas")
// }
// dependencies {
// //add("implementation", libs.findLibrary("room.runtime").get())
// //add("implementation", libs.findLibrary("room.ktx").get())
// //add("ksp", libs.findLibrary("room.compiler").get())
// }
val extension = extensions.getByType<LibraryExtension>().apply {
defaultConfig {
consumerProguardFile("consumer-rules.pro")
}
}
configureAndroidCompose(extension)
}
}
}