有一个Gradle6.X多模块项目使用Kotlin DSL。buildSrc
功能用于在中心位置管理依赖关系版本。类似于这里描述的方法。
该项目使用内部服务器来下载依赖项。它导致存储库设置配置在两个地方重复:
buildSrc/build.gradle.kts
:
plugins {
`kotlin-dsl`
}
repositories {
// The org.jetbrains.kotlin.jvm plugin requires a repository
// where to download the Kotlin compiler dependencies from.
maven {
url = uri("${extra.properties["custom.url"] as? String}")
credentials() {
username = extra.properties["custom.username"] as? String
password = extra.properties["custom.password"] as? String
}
}
}
根settings.gradle.kts
:
...
gradle.projectsLoaded {
allprojects {
repositories {
maven {
url = uri("${extra.properties["custom.url"] as? String}")
credentials() {
username = extra.properties["custom.username"] as? String
password = extra.properties["custom.password"] as? String
}
}
}
}
}
...
是否可以以某种方式在这两个位置之间共享重复的maven
块?
您可以尝试将kts
文件重构为这样的文件。这对你有帮助吗?
repositories.gradle.kts
:
repositories {
maven {
url = uri("${extra.properties["custom.url"] as? String}")
credentials() {
username = extra.properties["custom.username"] as? String
password = extra.properties["custom.password"] as? String
}
}
}
buildSrc/build.gradle.kts
plugins {
`kotlin-dsl`
}
apply(from="../repositories.gradle.kts")
settings.gradle.kts
gradle.projectsLoaded {
allprojects {
apply(from = "repositories.gradle.kts")
}
}