Gradle:在settings.Gradle.kts和buildSrc/build.Gradle-kts之间共享存储库



有一个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")
}
}

相关内容

  • 没有找到相关文章

最新更新