Skip to content

Commit 087907f

Browse files
committed
Fetch latest versions
1 parent ad65afa commit 087907f

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed
Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,57 @@
11
#!/usr/bin/env kotlin
22

33
import java.io.File
4+
import java.net.URL
5+
import javax.xml.parsers.DocumentBuilderFactory
46

57
fun main() {
6-
val kotlinVersion = "2.0.20-Beta1"
7-
val kspVersion = "2.0.20-Beta1-1.0.22"
8+
// Update versions in libraries.toml
9+
val kotlinVersion = getLatestVersion("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/org/jetbrains/kotlin/kotlin-stdlib/maven-metadata.xml")
10+
val kspVersion = getLatestVersion("https://oss.sonatype.org/content/repositories/snapshots/com/google/devtools/ksp/com.google.devtools.ksp.gradle.plugin/maven-metadata.xml")
11+
File("gradle/libraries.toml").let { file ->
12+
file.writeText(
13+
file.readText()
14+
.replaceVersion("kotlin-plugin", kotlinVersion)
15+
.replaceVersion("kotlin-plugin-max", kotlinVersion)
16+
.replaceVersion("kotlin-stdlib", kotlinVersion)
17+
.replaceVersion("ksp", kspVersion)
18+
)
19+
}
820

9-
val file = File("gradle/libraries.toml")
10-
val content = file.readText()
11-
.replaceVersion("kotlin-plugin", kotlinVersion)
12-
.replaceVersion("kotlin-plugin-max", kotlinVersion)
13-
.replaceVersion("kotlin-stdlib", kotlinVersion)
14-
.replaceVersion("ksp", kspVersion)
15-
file.writeText(content)
21+
// Uncomment Kotlin dev maven repository, add Sonatype snapshots repository
22+
setOf(
23+
File("gradle/repositories.gradle.kts"),
24+
File("intellij-plugin/build.gradle.kts"),
25+
)
26+
.forEach { file ->
27+
file.writeText(
28+
file.readText()
29+
.replace(
30+
"""// maven { url = uri("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/") }""",
31+
"""
32+
maven { url = uri("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/") }
33+
maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots/") }
34+
""".trimIndent()
35+
)
36+
)
37+
}
1638
}
1739

1840
fun String.replaceVersion(key: String, version: String): String {
1941
return replace(Regex("""$key = ".*""""), """$key = "$version"""")
2042
}
2143

44+
fun getLatestVersion(url: String): String {
45+
return URL(url)
46+
.openConnection()
47+
.getInputStream().use { inputStream ->
48+
DocumentBuilderFactory.newInstance()
49+
.newDocumentBuilder()
50+
.parse(inputStream)
51+
}
52+
.getElementsByTagName("latest")
53+
.item(0)
54+
.textContent
55+
}
56+
2257
main()

0 commit comments

Comments
 (0)