Skip to content

Commit 89d0478

Browse files
committed
QoL changes
1 parent 7029b68 commit 89d0478

File tree

8 files changed

+146
-92
lines changed

8 files changed

+146
-92
lines changed

build.gradle.kts

Lines changed: 6 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
*/
44

55
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
6-
import util.getSpacePassword
6+
import util.configureApiValidation
7+
import util.configureNpm
8+
import util.configureProjectReport
79
import util.libs
810

911
plugins {
1012
alias(libs.plugins.serialization) apply false
1113
alias(libs.plugins.kotlinx.rpc) apply false
1214
alias(libs.plugins.conventions.kover)
1315
alias(libs.plugins.conventions.gradle.doctor)
14-
alias(libs.plugins.binary.compatibility.validator)
1516

1617
if (libs.versions.atomicfu.get() >= "0.24.0") {
1718
alias(libs.plugins.atomicfu.new)
@@ -20,31 +21,9 @@ plugins {
2021
}
2122
}
2223

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

4928
val kotlinVersionFull: String by extra
5029

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

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: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
${registryUrl.removePrefix("https:")}:_authToken=$spacePassword
39+
""".trimIndent()
40+
}
41+
42+
buildYarnConfigFile.createNewFile()
43+
buildYarnConfigFile.writeText(outputYarnText)
44+
buildNpmConfigFile.createNewFile()
45+
buildNpmConfigFile.writeText(outputNpmText)
46+
}
47+
48+
outputs.file(buildYarnConfigFile).withPropertyName("buildOutputYarnFile")
49+
outputs.file(buildNpmConfigFile).withPropertyName("buildOutputNpmFile")
50+
}
51+
52+
plugins.withType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin::class.java).configureEach {
53+
rootProject.extensions.configure<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension> {
54+
download = true
55+
downloadBaseUrl = "https://packages.jetbrains.team/files/p/krpc/build-deps/"
56+
}
57+
58+
tasks.named("kotlinNpmInstall").configure {
59+
dependsOn(executeNpmLogin)
60+
}
61+
}
62+
63+
// necessary for CI js tests
64+
rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin> {
65+
rootProject.extensions.configure<org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension> {
66+
ignoreScripts = false
67+
download = true
68+
downloadBaseUrl = "https://packages.jetbrains.team/files/p/krpc/build-deps/"
69+
}
70+
}
71+
}
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
@@ -97,6 +97,7 @@ coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", ve
9797
coroutines-debug = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-debug", version.ref = "coroutines" }
9898
detekt-gradle-plugin = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version.ref = "detekt-gradle-plugin" }
9999
kover-gradle-plugin = { module = "org.jetbrains.kotlinx:kover-gradle-plugin", version.ref = "kover" }
100+
binary-compatibility-validator-gradle-plugin = { module = "org.jetbrains.kotlinx:binary-compatibility-validator", version.ref = "binary-compatibility-validator" }
100101
kotlin-js-wrappers = { module = "org.jetbrains.kotlin-wrappers:kotlin-js", version.ref = "kotlin-wrappers" }
101102
gradle-kotlin-dsl-pluigns = { module = "org.gradle.kotlin:gradle-kotlin-dsl-plugins", version.ref = "gradle-kotlin-dsl" }
102103
intellij-util = { module = "com.jetbrains.intellij.platform:util", version.ref = "intellij" }
@@ -124,6 +125,7 @@ conventions-kmp = { id = "conventions-kmp", version.ref = "kotlinx-rpc" }
124125
conventions-gradle-publish = { id = "conventions-gradle-publish", version.ref = "kotlinx-rpc" }
125126
conventions-kover = { id = "conventions-kover", version.ref = "kotlinx-rpc" }
126127
conventions-gradle-doctor = { id = "conventions-gradle-doctor", version.ref = "kotlinx-rpc" }
128+
conventions-npm = { id = "conventions-npm", version.ref = "kotlinx-rpc" }
127129
compiler-specific-module = { id = "compiler-specific-module", version.ref = "kotlinx-rpc" }
128130

129131
# gradle-plugin project

0 commit comments

Comments
 (0)