There is a Gradle 6.X multi-module project using Kotlin DSL.
buildSrc
feature is used to manage dependency versions in a central place. Something similar to the approach described here.
The project uses an internal server to download dependencies. It causes the duplication of the repository settings configuration in two places:
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
}
}
}
and root 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
}
}
}
}
}
...
Is it possible somehow to share the duplicated maven
block between these two places?
You could try refactoring your kts
file into something like this. Does this help you?
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")
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With