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) {
|
from(samplesDir) {
|
||||||
it.include("**/*.gradle")
|
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")
|
it.include("**/*.gradle.kts")
|
||||||
val replacements = replacementsWithWrapper { s -> "maven(\"$s\")"}
|
|
||||||
it.filter { line ->
|
it.filter { line ->
|
||||||
val repo = line.trim()
|
replacements.forEach { (repo, replacement) ->
|
||||||
replacements[repo]?.let { r -> line.replace(repo, r) } ?: line
|
if (line.contains(repo)) {
|
||||||
|
return@filter line.replace(repo, replacement)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return@filter line
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
from(samplesDir) {
|
from(samplesDir) {
|
||||||
@@ -61,22 +57,12 @@ open class CopySamples : Copy() {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun replacementsWithWrapper(wrap: (String) -> String) =
|
private val replacements = listOf(
|
||||||
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(
|
|
||||||
"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-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/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://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"
|
"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\") }",
|
||||||
private val centralReplacements = mapOf(
|
|
||||||
"mavenCentral()" to "https://cache-redirector.jetbrains.com/maven-central",
|
|
||||||
"jcenter()" to "https://cache-redirector.jetbrains.com/jcenter",
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user