arekolek
02/27/2024, 11:09 AMRepositoryHandler.myProxy()
in settings.gradle.kts
?
fun RepositoryHandler.myProxy(repository: String, fallbackUrl: String? = null, vararg includeGroups: String) {
maven("<https://example.com/$repository/>") {
content { includeGroups.forEach(::includeGroup) }
credentials {
username = providers.gradleProperty("MY_PROXY_USERNAME").get()
password = providers.gradleProperty("MY_PROXY_PASSWORD").get()
}
}
if (fallbackUrl == null) return
maven(fallbackUrl) {
content { includeGroups.forEach(::includeGroup) }
}
}
I would like to use it like:
pluginManagement {
repositories {
gradlePluginPortal()
google()
myProxy("maven-central")
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
myProxy("jitpack-io", "<https://jitpack.io>", "com.example")
google()
myProxy("maven-central")
mavenCentral()
}
}
but I would have to repeat the definition in both pluginManagement
and dependencyResolutionManagement
is there any way to re-use the same definition in both? I don't see why that should be impossible (since it works if I just duplicate it)Sam
02/27/2024, 11:15 AMSam
02/27/2024, 11:16 AMVampire
02/27/2024, 11:20 AMpluginManagement { ... }
is like buildscript { ... }
and plugins { ... }
.
It is extracted and evaluated separately first, as you could for example declare repositories where to get settings plugins from or define an included build that contributes settings plugins.
So you cannot use anything from outside the pluginManagement { ... }
block inside the block even though the IDE is happy.Vampire
02/27/2024, 11:21 AMpluginManagement { ... }
block though.
So this works:
// the plugin management block is evaluated first separately, do not change this to
// listOf(pluginManagement.repositories, dependencyResolutionManagement.repositories)
// instead that would change the semantics
pluginManagement {
listOf(repositories, dependencyResolutionManagement.repositories).forEach { repositories ->
repositories.apply {
maven("...") {
...
}
}
}
}
arekolek
02/27/2024, 11:22 AM