Skip to content

Commit 29a588c

Browse files
authored
Fix how we create 'publishMavenArtifact' tasks (#416)
1 parent 177dff3 commit 29a588c

File tree

5 files changed

+34
-25
lines changed

5 files changed

+34
-25
lines changed

gradle-conventions/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
plugins {

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,11 @@ fun KotlinCommonCompilerOptions.setProjectLanguageVersion() {
3232
withKotlinJvmExtension {
3333
optInForRpcApi()
3434

35-
target.compilations
36-
.filter { it.isMain }
37-
.forEach { compilation ->
38-
compilation.compileJavaTaskProvider.configure {
39-
compilerOptions.setProjectLanguageVersion()
40-
}
41-
}
35+
compilerOptions.setProjectLanguageVersion()
4236
}
4337

4438
withKotlinKmpExtension {
4539
optInForRpcApi()
4640

47-
targets.flatMap { it.compilations }
48-
.filter { it.isMain }
49-
.forEach { compilation ->
50-
compilation.compileTaskProvider.configure {
51-
compilerOptions.setProjectLanguageVersion()
52-
}
53-
}
41+
compilerOptions.setProjectLanguageVersion()
5442
}
55-
56-
val KotlinCompilation<*>.isMain get() = name.lowercase().contains("main")

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import org.gradle.kotlin.dsl.registering
66
import util.*
7+
import util.other.capitalized
78
import util.other.getSensitiveProperty
89
import util.other.isPublicModule
910
import util.tasks.ValidatePublishedArtifactsTask
@@ -21,7 +22,23 @@ if (isPublicModule) {
2122
apply(plugin = "signing")
2223
}
2324

24-
the<PublishingExtension>().configurePublication()
25+
the<PublishingExtension>().apply {
26+
configurePublication()
27+
28+
project.withKotlinKmpExtension {
29+
// Remove then first Jvm Only public module is created
30+
val publishMavenPublication = "publishMavenPublication"
31+
repositories.all {
32+
val publishTaskName = "${publishMavenPublication}To${name.capitalized()}Repository"
33+
if (tasks.findByName(publishTaskName) == null) {
34+
tasks.register(publishTaskName) {
35+
group = PublishingPlugin.PUBLISH_TASK_GROUP
36+
}
37+
}
38+
}
39+
}
40+
}
41+
2542
logger.info("Configured ${project.name} for publication")
2643
} else {
2744
logger.info("Skipping ${project.name} publication configuration, not a public module")

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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.capitalized
56
import util.other.isPublicModule
67
import util.other.libs
78
import util.other.maybeNamed
@@ -34,13 +35,6 @@ tasks.register<ValidatePublishedArtifactsTask>(ValidatePublishedArtifactsTask.NA
3435
dependsOn(subprojects.filter { it.isPublicModule })
3536
}
3637

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-
4438
dokka {
4539
val libVersion = libs.versions.kotlinx.rpc.get()
4640

gradle-plugin/build.gradle.kts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
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 org.jetbrains.kotlin.gradle.tasks.KotlinCompile
6+
7+
/*
8+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
9+
*/
510

611
plugins {
712
`kotlin-dsl`
@@ -18,6 +23,13 @@ kotlin {
1823
explicitApi()
1924
}
2025

26+
tasks.withType<KotlinCompile>().configureEach {
27+
compilerOptions {
28+
apiVersion = org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_0
29+
languageVersion = org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_0
30+
}
31+
}
32+
2133
dependencies {
2234
compileOnly(libs.kotlin.gradle.plugin)
2335
}

0 commit comments

Comments
 (0)