I have a functions that’s an alternative to mavenCentral
, which creates an ArtifactRepository:
fun RepositoryHandler.myCustomRepository(): ArtifactRepository {
// about 20 lines of code
}
I have a multi-project Gradle build that also has a buildSrc
, and I want to
use myCustomRepository
:
- for both dependency loading and plugin loading
- in my root project, all subprojects, and in
buildSrc
The best I’ve found is to use settings.gradle.kts
and
buildSrc/settings.gradle.kts
and use the function in four places:
- settings.gradle.kts in pluginManagement
- settings.gradle.kts in dependencyResolutionManagement
- buildSrc/settings.gradle.kts in pluginManagement
- buildSrc/settings.gradle.kts in dependencyResolutionManagement
Unfortunately,
it seems that I also need to define four identical copies of the function,
two in each settings.gradle.kts
file. I haven’t been able to find a single place
to define it that’s visible to all four locations where I need to use it.
That is:
settings.gradle.kts
fun RepositoryHandler.myCustomRepository(): ArtifactRepository {
// copy #1
}
pluginManagement {
fun RepositoryHandler.myCustomRepository(): ArtifactRepository {
// copy #2
}
repositories {
myCustomRepository()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositories {
myCustomRepository()
}
}
buildSrc/settings.gradle.kts
fun RepositoryHandler.myCustomRepository(): ArtifactRepository {
// copy #3
}
pluginManagement {
fun RepositoryHandler.myCustomRepository(): ArtifactRepository {
// copy #4
}
repositories {
myCustomRepository()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositories {
myCustomRepository()
gradlePluginPortal()
}
}
Is there some way to define this function in only ONE place, and use it in
all four of these places?