|
1 | 1 | #!/usr/bin/env kotlin |
2 | 2 |
|
3 | 3 | import java.io.File |
| 4 | +import java.net.URL |
| 5 | +import javax.xml.parsers.DocumentBuilderFactory |
4 | 6 |
|
5 | 7 | 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 | + } |
8 | 20 |
|
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 | + } |
16 | 38 | } |
17 | 39 |
|
18 | 40 | fun String.replaceVersion(key: String, version: String): String { |
19 | 41 | return replace(Regex("""$key = ".*""""), """$key = "$version"""") |
20 | 42 | } |
21 | 43 |
|
| 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 | + |
22 | 57 | main() |
0 commit comments