Skip to content

Commit b2655e6

Browse files
authored
Added artifacts validation (#377)
1 parent c4a5721 commit b2655e6

23 files changed

+1378
-22
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ allprojects {
2121
version = rootProject.libs.versions.kotlinx.rpc.get()
2222
}
2323

24-
println("[Core] kotlinx.rpc project version: $version, Kotlin version: $kotlinVersion, Compiler: $kotlinCompiler")
24+
logger.lifecycle("[Core] kotlinx.rpc project version: $version, Kotlin version: $kotlinVersion, Compiler: $kotlinCompiler")
2525

2626
// If the prefix of the kPRC version is not Kotlin gradle plugin version – you have a problem :)
2727
// Probably some dependency brings kotlin with the later version.

compiler-plugin/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ allprojects {
2222
}
2323
}
2424

25-
println(
25+
logger.lifecycle(
2626
"[Compiler Plugin] kotlinx.rpc project version: $version, " +
2727
"Kotlin version: $kotlinLangVersion, " +
2828
"Compiler version: $kotlinCompilerVersion"
2929
)
3030

3131
whenForIde {
32-
println("[Compiler Plugin] For-ide project mode enabled")
32+
logger.lifecycle("[Compiler Plugin] For-ide project mode enabled")
3333
}

docs/environment.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ Before pushing, run (maybe separately):
153153
```
154154

155155
Beware, that `detekt` doesn't fail the build, but outputs messages into the console.
156-
Makes sense to run it separately. You can also see generated reports
156+
Makes sense to run it separately. You can also see generated reports
157+
158+
Also, artifact checks: `./validatePublishedArtifacts.sh -s`.
159+
See the [section](#tasks-to-know-about) below.
157160

158161
### How to work with the compiler plugin
159162

@@ -486,6 +489,11 @@ usually after Kotlin version update.
486489
- `clean` - everything
487490
- `cleanTest` - JVM test results
488491
- `cleanAllTests` - KMP test results
492+
- `validatePublishedArtifacts` task and more importantly `./validatePublishedArtifacts.sh` script.
493+
494+
They are used to validate published artifacts and ensure you didn't delete or published something accidentally.
495+
496+
Available options: `--dump` - update files, `-s` - no Gradle output except for errors, `-v` - verbose output.
489497

490498
## Other
491499

dokka-plugin/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ plugins {
1010
group = "org.jetbrains.kotlinx"
1111
version = libs.versions.kotlinx.rpc.get()
1212

13-
println("[Dokka Plugin] kotlinx.rpc project version: $version, Kotlin version: ${libs.versions.kotlin.lang.get()}")
13+
logger.lifecycle("[Dokka Plugin] kotlinx.rpc project version: $version, Kotlin version: ${libs.versions.kotlin.lang.get()}")
1414

1515
kotlin {
1616
jvmToolchain(8)

gradle-conventions/src/main/kotlin/compiler-specific-module.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5-
import gradle.kotlin.dsl.accessors._46680087f5e33e6a2d850d9e9b86aaa7.main
65
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
76
import util.csm.ProcessCsmTemplate
87
import util.other.libs
98
import kotlin.io.path.createDirectories
109

1110
val kotlin = the<KotlinJvmProjectExtension>()
1211

13-
val templatesDir = kotlin.sourceSets.main.map {
12+
val mainSourceSet = kotlin.sourceSets.named("main")
13+
val templatesDir = mainSourceSet.map {
1414
it.kotlin.srcDirs.single { dir -> dir.name == "kotlin" }.toPath().parent.resolve("templates")
1515
}
1616

@@ -28,6 +28,6 @@ val processCsmTemplates =
2828
sourcesDir,
2929
)
3030

31-
kotlin.sourceSets.main {
31+
mainSourceSet.configure {
3232
kotlin.srcDirs(processCsmTemplates.map { it.sourcesDir })
3333
}

gradle-conventions/src/main/kotlin/conventions-publishing.gradle.kts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import org.gradle.kotlin.dsl.registering
66
import util.*
77
import util.other.getSensitiveProperty
88
import util.other.isPublicModule
9+
import util.tasks.ValidatePublishedArtifactsTask
910

1011
val isGradlePlugin = project.name == "gradle-plugin"
1112
val publishingExtension = project.extensions.findByType<PublishingExtension>()
@@ -28,7 +29,6 @@ if (isPublicModule) {
2829

2930
fun PublishingExtension.configurePublication() {
3031
repositories {
31-
configureSonatypeRepository()
3232
configureSpaceRepository()
3333
configureForIdeRepository()
3434
configureLocalDevRepository()
@@ -138,15 +138,6 @@ fun RepositoryHandler.configureLocalDevRepository() {
138138
}
139139
}
140140

141-
fun RepositoryHandler.configureSonatypeRepository() {
142-
configureRepository(project) {
143-
username = "libs.sonatype.user"
144-
password = "libs.sonatype.password"
145-
name = "sonatype"
146-
url = sonatypeRepositoryUri
147-
}
148-
}
149-
150141
val sonatypeRepositoryUri: String?
151142
get() {
152143
val repositoryId: String = project.getSensitiveProperty("libs.repository.id")
@@ -166,6 +157,10 @@ fun configureEmptyJavadocArtifact(): TaskProvider<Jar?> {
166157
}
167158

168159
fun MavenPublication.signPublicationIfKeyPresent() {
160+
if (gradle.startParameter.taskNames.contains(ValidatePublishedArtifactsTask.NAME)) {
161+
return
162+
}
163+
169164
val keyId = project.getSensitiveProperty("libs.sign.key.id")
170165
val signingKey = project.getSensitiveProperty("libs.sign.key.private")
171166
val signingKeyPassphrase = project.getSensitiveProperty("libs.sign.passphrase")

gradle-conventions/src/main/kotlin/conventions-root.gradle.kts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5+
import util.other.isPublicModule
56
import util.other.libs
7+
import util.other.maybeNamed
8+
import util.tasks.ValidatePublishedArtifactsTask
69
import util.tasks.configureNpm
710
import util.tasks.registerChangelogTask
811
import util.tasks.registerDumpPlatformTableTask
@@ -27,6 +30,17 @@ allprojects {
2730
plugins.apply("project-report")
2831
}
2932

33+
tasks.register<ValidatePublishedArtifactsTask>(ValidatePublishedArtifactsTask.NAME) {
34+
dependsOn(subprojects.filter { it.isPublicModule })
35+
}
36+
37+
// Remove then first Jvm Only public module is created
38+
val publishMavenPublicationToBuildRepoRepository = "publishMavenPublicationToBuildRepoRepository"
39+
tasks.maybeNamed(publishMavenPublicationToBuildRepoRepository)
40+
?: tasks.register(publishMavenPublicationToBuildRepoRepository) {
41+
group = PublishingPlugin.PUBLISH_TASK_GROUP
42+
}
43+
3044
dokka {
3145
val libVersion = libs.versions.kotlinx.rpc.get()
3246

@@ -84,7 +98,7 @@ registerDumpPlatformTableTask()
8498
registerVerifyPlatformTableTask()
8599
registerChangelogTask()
86100

87-
fun Project.forEachSubproject(action: (String, Path, Path) -> Unit) {
101+
fun Project.forEachIncludedProject(action: (String, Path, Path) -> Unit) {
88102
val globalRootDir: String by extra
89103
val root = Path.of(globalRootDir)
90104
val rootProperties = root.resolve("gradle.properties").readText()
@@ -100,7 +114,7 @@ fun Project.forEachSubproject(action: (String, Path, Path) -> Unit) {
100114
}
101115

102116
val updateProperties = tasks.register("updateProperties") {
103-
forEachSubproject { rootProperties, _, subProjectProperties ->
117+
forEachIncludedProject { rootProperties, _, subProjectProperties ->
104118
if (!subProjectProperties.exists()) {
105119
subProjectProperties.createFile()
106120
}
@@ -114,7 +128,7 @@ gradle.afterProject {
114128
return@afterProject
115129
}
116130

117-
forEachSubproject { rootProperties, parent, subProjectProperties ->
131+
forEachIncludedProject { rootProperties, parent, subProjectProperties ->
118132
if (!subProjectProperties.exists() || subProjectProperties.readText() != rootProperties) {
119133
throw GradleException(
120134
"'gradle.properties' file in ${parent.name} included project is not up-to-date with root. " +
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package util.other
6+
7+
fun String.capitalized() = replaceFirstChar(Char::titlecase)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package util.other
6+
7+
import org.gradle.api.NamedDomainObjectCollection
8+
import org.gradle.api.NamedDomainObjectProvider
9+
10+
internal fun <T> NamedDomainObjectCollection<T>.maybeNamed(name: String): NamedDomainObjectProvider<T>? {
11+
return if (name in names) named(name) else null
12+
}
13+
14+
internal fun <T> NamedDomainObjectCollection<T>.maybeNamed(name: String, configure: T.() -> Unit) {
15+
if (name in names) named(name).configure(configure)
16+
}

gradle-conventions/src/main/kotlin/util/targets/configure.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
1313
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
1414
import util.kmp
1515
import util.setPublicArtifactId
16+
import kotlin.collections.map
1617

1718
private fun KotlinMultiplatformExtension.configureTargets(config: KmpConfig): List<KotlinTarget> {
1819
val targets = mutableListOf<KotlinTarget>()
1920

2021
if (config.native) {
2122
val nativeTargets = config.nativeTargets(this)
2223
targets.addAll(nativeTargets)
24+
config.project.configureNativePublication(nativeTargets)
2325
}
2426

2527
if (config.jvm) {

0 commit comments

Comments
 (0)