Use maven { setUrl("...") } that works both for .gradle.kts and .gradle files
This commit is contained in:
committed by
Stanislav Erokhin
parent
4638988c2f
commit
e1d9a36de3
@@ -22,18 +22,14 @@ open class CopySamples : Copy() {
|
||||
}
|
||||
from(samplesDir) {
|
||||
it.include("**/*.gradle")
|
||||
val replacements = replacementsWithWrapper { s -> "maven { url '$s' }" }
|
||||
it.filter { line ->
|
||||
val repo = line.trim()
|
||||
replacements[repo]?.let { r -> line.replace(repo, r) } ?: line
|
||||
}
|
||||
}
|
||||
from(samplesDir) {
|
||||
it.include("**/*.gradle.kts")
|
||||
val replacements = replacementsWithWrapper { s -> "maven(\"$s\")"}
|
||||
it.filter { line ->
|
||||
val repo = line.trim()
|
||||
replacements[repo]?.let { r -> line.replace(repo, r) } ?: line
|
||||
replacements.forEach { (repo, replacement) ->
|
||||
if (line.contains(repo)) {
|
||||
return@filter line.replace(repo, replacement)
|
||||
}
|
||||
}
|
||||
return@filter line
|
||||
}
|
||||
}
|
||||
from(samplesDir) {
|
||||
@@ -61,22 +57,12 @@ open class CopySamples : Copy() {
|
||||
return this
|
||||
}
|
||||
|
||||
private fun replacementsWithWrapper(wrap: (String) -> String) =
|
||||
urlReplacements.map { entry ->
|
||||
Pair(wrap(entry.key), wrap(entry.value))
|
||||
}.toMap() + centralReplacements.map { entry ->
|
||||
Pair(entry.key, wrap(entry.value))
|
||||
}.toMap()
|
||||
|
||||
private val urlReplacements = mapOf(
|
||||
private val replacements = listOf(
|
||||
"https://dl.bintray.com/kotlin/kotlin-dev" to "https://cache-redirector.jetbrains.com/dl.bintray.com/kotlin/kotlin-dev",
|
||||
"https://dl.bintray.com/kotlin/kotlin-eap" to "https://cache-redirector.jetbrains.com/dl.bintray.com/kotlin/kotlin-eap",
|
||||
"https://dl.bintray.com/kotlin/ktor" to "https://cache-redirector.jetbrains.com/dl.bintray.com/kotlin/ktor",
|
||||
"https://plugins.gradle.org/m2" to "https://cache-redirector.jetbrains.com/plugins.gradle.org/m2"
|
||||
)
|
||||
|
||||
private val centralReplacements = mapOf(
|
||||
"mavenCentral()" to "https://cache-redirector.jetbrains.com/maven-central",
|
||||
"jcenter()" to "https://cache-redirector.jetbrains.com/jcenter",
|
||||
"https://plugins.gradle.org/m2" to "https://cache-redirector.jetbrains.com/plugins.gradle.org/m2",
|
||||
"mavenCentral()" to "maven { setUrl(\"https://cache-redirector.jetbrains.com/maven-central\") }",
|
||||
"jcenter()" to "maven { setUrl(\"https://cache-redirector.jetbrains.com/jcenter\") }",
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user