Skip to content

Commit 1618b69

Browse files
committed
QoL changes
1 parent 73ec3a6 commit 1618b69

File tree

8 files changed

+144
-91
lines changed

8 files changed

+144
-91
lines changed

build.gradle.kts

Lines changed: 3 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,12 @@ plugins {
1111
alias(libs.plugins.kotlinx.rpc) apply false
1212
alias(libs.plugins.conventions.kover)
1313
alias(libs.plugins.conventions.gradle.doctor)
14-
alias(libs.plugins.binary.compatibility.validator)
1514
alias(libs.plugins.atomicfu)
1615
}
1716

18-
// useful for dependencies introspection
19-
// run ./gradlew htmlDependencyReport
20-
// Report can normally be found in build/reports/project/dependencies/index.html
21-
allprojects {
22-
plugins.apply("project-report")
23-
}
24-
25-
object Const {
26-
const val INTERNAL_RPC_API_ANNOTATION = "kotlinx.rpc.internal.utils.InternalRPCApi"
27-
}
28-
29-
apiValidation {
30-
ignoredPackages.add("kotlinx.rpc.internal")
31-
ignoredPackages.add("kotlinx.rpc.krpc.internal")
32-
33-
ignoredProjects.addAll(
34-
listOf(
35-
"compiler-plugin-tests",
36-
"krpc-test",
37-
"utils",
38-
)
39-
)
40-
41-
nonPublicMarkers.add(Const.INTERNAL_RPC_API_ANNOTATION)
42-
}
17+
configureProjectReport()
18+
configureNpm()
19+
configureApiValidation()
4320

4421
val kotlinVersionFull: String by extra
4522

@@ -58,62 +35,3 @@ val kotlinGPVersion = getKotlinPluginVersion()
5835
if (kotlinVersionFull != kotlinGPVersion) {
5936
error("KGP version mismatch. Project version: $kotlinVersionFull, KGP version: $kotlinGPVersion")
6037
}
61-
62-
val executeNpmLogin by tasks.registering {
63-
val registryUrl = "https://packages.jetbrains.team/npm/p/krpc/build-deps/"
64-
65-
// To prevent leaking of credentials in VCS on dev machine use the build directory config file
66-
val buildYarnConfigFile = File(project.rootDir, "build/js/.yarnrc")
67-
val buildNpmConfigFile = File(project.rootDir, "build/js/.npmrc")
68-
69-
val spacePassword: String? = getSpacePassword()
70-
71-
doLast {
72-
val outputYarnText = """
73-
registry: "$registryUrl"
74-
""".trimIndent()
75-
76-
var outputNpmText = """
77-
registry: "$registryUrl"
78-
""".trimIndent()
79-
80-
if (spacePassword != null) {
81-
if (spacePassword.split(".").size != 3) {
82-
throw GradleException("Unexpected Space Token format")
83-
}
84-
85-
outputNpmText += System.lineSeparator() + """
86-
always-auth: true
87-
${registryUrl.removePrefix("https:")}:_authToken=$spacePassword
88-
""".trimIndent()
89-
}
90-
91-
buildYarnConfigFile.createNewFile()
92-
buildYarnConfigFile.writeText(outputYarnText)
93-
buildNpmConfigFile.createNewFile()
94-
buildNpmConfigFile.writeText(outputNpmText)
95-
}
96-
97-
outputs.file(buildYarnConfigFile).withPropertyName("buildOutputYarnFile")
98-
outputs.file(buildNpmConfigFile).withPropertyName("buildOutputNpmFile")
99-
}
100-
101-
plugins.withType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin::class.java).configureEach {
102-
rootProject.extensions.configure(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension::class.java) {
103-
download = true
104-
downloadBaseUrl = "https://packages.jetbrains.team/files/p/krpc/build-deps/"
105-
}
106-
107-
tasks.named("kotlinNpmInstall").configure {
108-
dependsOn(executeNpmLogin)
109-
}
110-
}
111-
112-
// necessary for CI js tests
113-
rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin> {
114-
rootProject.extensions.configure<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension> {
115-
ignoreScripts = false
116-
download = true
117-
downloadBaseUrl = "https://packages.jetbrains.team/files/p/krpc/build-deps/"
118-
}
119-
}

gradle-conventions-settings/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ val isLatestKotlinVersion: Boolean by extra
2020
dependencies {
2121
api(libs.kotlin.gradle.plugin)
2222
api(libs.detekt.gradle.plugin)
23+
api(libs.binary.compatibility.validator.gradle.plugin)
2324

2425
if (isLatestKotlinVersion) {
2526
api(libs.kover.gradle.plugin)

gradle-conventions-settings/src/main/kotlin/conventions-repositories.settings.gradle.kts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,21 @@ pluginManagement {
1111
return null
1212
}
1313

14+
fun getEnv(propertyName: String): String? = System.getenv(
15+
propertyName.replace(".", "_").uppercase()
16+
)?.ifEmpty { null }
17+
1418
fun getSpaceUsername(): String? {
1519
val username = "kotlinx.rpc.team.space.username"
1620
return settings.providers.gradleProperty(username).orNull
17-
?: System.getenv(username)?.ifEmpty { null }
21+
?: getEnv(username)
1822
?: logAbsentProperty(username)
1923
}
2024

2125
fun getSpacePassword(): String? {
2226
val password = "kotlinx.rpc.team.space.password"
2327
return settings.providers.gradleProperty(password).orNull
24-
?: System.getenv(password)?.ifEmpty { null }
28+
?: getEnv(password)
2529
?: logAbsentProperty(password)
2630
}
2731

@@ -43,6 +47,8 @@ pluginManagement {
4347
username = spaceUsername
4448
password = spacePassword
4549
}
50+
} else {
51+
logger.info("Skipping adding credentials for Space repository '$repoName'")
4652
}
4753
}
4854
}
@@ -63,17 +69,21 @@ gradle.rootProject {
6369
return null
6470
}
6571

72+
fun getEnv(propertyName: String): String? = System.getenv(
73+
propertyName.replace(".", "_").uppercase()
74+
)?.ifEmpty { null }
75+
6676
fun getSpaceUsername(): String? {
6777
val username = "kotlinx.rpc.team.space.username"
6878
return settings.providers.gradleProperty(username).orNull
69-
?: System.getenv(username)?.ifEmpty { null }
79+
?: getEnv(username)
7080
?: logAbsentProperty(username)
7181
}
7282

7383
fun getSpacePassword(): String? {
7484
val password = "kotlinx.rpc.team.space.password"
7585
return settings.providers.gradleProperty(password).orNull
76-
?: System.getenv(password)?.ifEmpty { null }
86+
?: getEnv(password)
7787
?: logAbsentProperty(password)
7888
}
7989

@@ -96,6 +106,8 @@ gradle.rootProject {
96106
username = spaceUsername
97107
password = spacePassword
98108
}
109+
} else {
110+
logger.info("Skipping adding credentials for Space repository '$repoName'")
99111
}
100112
}
101113
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package util
6+
7+
import kotlinx.validation.ApiValidationExtension
8+
import org.gradle.api.Project
9+
import org.gradle.kotlin.dsl.the
10+
11+
fun Project.configureApiValidation() {
12+
plugins.apply(libs.plugins.binary.compatibility.validator.get().pluginId)
13+
14+
the<ApiValidationExtension>().apply {
15+
ignoredPackages.add("kotlinx.rpc.internal")
16+
ignoredPackages.add("kotlinx.rpc.krpc.internal")
17+
18+
ignoredProjects.addAll(
19+
listOf(
20+
"compiler-plugin-tests",
21+
"krpc-test",
22+
"utils",
23+
)
24+
)
25+
26+
nonPublicMarkers.add("kotlinx.rpc.internal.utils.InternalRPCApi")
27+
}
28+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package util
6+
7+
import org.gradle.api.GradleException
8+
import org.gradle.api.Project
9+
import org.gradle.kotlin.dsl.*
10+
import java.io.File
11+
12+
fun Project.configureNpm() {
13+
val executeNpmLogin by tasks.registering {
14+
val registryUrl = "https://packages.jetbrains.team/npm/p/krpc/build-deps/"
15+
16+
// To prevent leaking of credentials in VCS on dev machine use the build directory config file
17+
val buildYarnConfigFile = File(project.rootDir, "build/js/.yarnrc")
18+
val buildNpmConfigFile = File(project.rootDir, "build/js/.npmrc")
19+
20+
val spacePassword: String? = getSpacePassword()
21+
22+
doLast {
23+
val outputYarnText = """
24+
registry: "$registryUrl"
25+
""".trimIndent()
26+
27+
var outputNpmText = """
28+
registry="$registryUrl"
29+
""".trimIndent()
30+
31+
if (spacePassword != null) {
32+
if (spacePassword.split(".").size != 3) {
33+
throw GradleException("Unexpected Space Token format")
34+
}
35+
36+
outputNpmText += System.lineSeparator() + """
37+
always-auth=true
38+
save-exact=true
39+
${registryUrl.removePrefix("https:")}:_authToken=$spacePassword
40+
""".trimIndent()
41+
}
42+
43+
buildYarnConfigFile.createNewFile()
44+
buildYarnConfigFile.writeText(outputYarnText)
45+
buildNpmConfigFile.createNewFile()
46+
buildNpmConfigFile.writeText(outputNpmText)
47+
}
48+
49+
outputs.file(buildYarnConfigFile).withPropertyName("buildOutputYarnFile")
50+
outputs.file(buildNpmConfigFile).withPropertyName("buildOutputNpmFile")
51+
}
52+
53+
plugins.withType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin::class.java).configureEach {
54+
rootProject.extensions.configure<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension> {
55+
download = true
56+
downloadBaseUrl = "https://packages.jetbrains.team/files/p/krpc/build-deps/"
57+
}
58+
59+
tasks.named("kotlinNpmInstall").configure {
60+
dependsOn(executeNpmLogin)
61+
}
62+
}
63+
64+
// necessary for CI js tests
65+
rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin> {
66+
rootProject.extensions.configure<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension> {
67+
ignoreScripts = false
68+
download = true
69+
downloadBaseUrl = "https://packages.jetbrains.team/files/p/krpc/build-deps/"
70+
}
71+
}
72+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package util
6+
7+
import org.gradle.api.Project
8+
9+
// useful for dependencies introspection
10+
// run ./gradlew htmlDependencyReport
11+
// Report can normally be found in build/reports/project/dependencies/index.html
12+
fun Project.configureProjectReport() {
13+
allprojects {
14+
plugins.apply("project-report")
15+
}
16+
}

gradle-conventions-settings/src/main/kotlin/util/properties.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,22 @@ fun Project.logAbsentProperty(name: String): Nothing? {
1414
return null
1515
}
1616

17+
fun getEnv(propertyName: String): String? = System.getenv(
18+
propertyName.replace(".", "_").uppercase()
19+
)?.ifEmpty { null }
20+
1721
private const val SPACE_USERNAME = "kotlinx.rpc.team.space.username"
1822

1923
fun Project.getSpaceUsername(): String? {
2024
return providers.gradleProperty(SPACE_USERNAME).orNull
21-
?: System.getenv(SPACE_USERNAME)?.ifEmpty { null }
25+
?: getEnv(SPACE_USERNAME)
2226
?: logAbsentProperty(SPACE_USERNAME)
2327
}
2428

2529
private const val SPACE_PASSWORD = "kotlinx.rpc.team.space.password"
2630

2731
fun Project.getSpacePassword(): String? {
2832
return providers.gradleProperty(SPACE_PASSWORD).orNull
29-
?: System.getenv(SPACE_PASSWORD)?.ifEmpty { null }
33+
?: getEnv(SPACE_PASSWORD)
3034
?: logAbsentProperty(SPACE_USERNAME)
3135
}

versions-root/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", ve
9292
coroutines-debug = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-debug", version.ref = "coroutines" }
9393
detekt-gradle-plugin = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version.ref = "detekt-gradle-plugin" }
9494
kover-gradle-plugin = { module = "org.jetbrains.kotlinx:kover-gradle-plugin", version.ref = "kover" }
95+
binary-compatibility-validator-gradle-plugin = { module = "org.jetbrains.kotlinx:binary-compatibility-validator", version.ref = "binary-compatibility-validator" }
9596
kotlin-js-wrappers = { module = "org.jetbrains.kotlin-wrappers:kotlin-js", version.ref = "kotlin-wrappers" }
9697
gradle-kotlin-dsl-pluigns = { module = "org.gradle.kotlin:gradle-kotlin-dsl-plugins", version.ref = "gradle-kotlin-dsl" }
9798
intellij-util = { module = "com.jetbrains.intellij.platform:util", version.ref = "intellij" }
@@ -117,6 +118,7 @@ conventions-kmp = { id = "conventions-kmp", version.ref = "kotlinx-rpc" }
117118
conventions-gradle-publish = { id = "conventions-gradle-publish", version.ref = "kotlinx-rpc" }
118119
conventions-kover = { id = "conventions-kover", version.ref = "kotlinx-rpc" }
119120
conventions-gradle-doctor = { id = "conventions-gradle-doctor", version.ref = "kotlinx-rpc" }
121+
conventions-npm = { id = "conventions-npm", version.ref = "kotlinx-rpc" }
120122
compiler-specific-module = { id = "compiler-specific-module", version.ref = "kotlinx-rpc" }
121123

122124
# gradle-plugin project

0 commit comments

Comments
 (0)