Skip to content

Commit 0b5d334

Browse files
authored
Fix build config for for-ide builds (#287)
1 parent 4907cad commit 0b5d334

File tree

15 files changed

+86
-55
lines changed

15 files changed

+86
-55
lines changed

compiler-plugin/compiler-plugin-backend/build.gradle.kts

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
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
import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode
6+
import util.otherwise
7+
import util.whenForIde
68

79
plugins {
810
alias(libs.plugins.conventions.jvm)
@@ -18,6 +20,11 @@ kotlin {
1820
}
1921

2022
dependencies {
21-
compileOnly(libs.kotlin.compiler.embeddable)
23+
whenForIde {
24+
compileOnly(libs.kotlin.compiler)
25+
} otherwise {
26+
compileOnly(libs.kotlin.compiler.embeddable)
27+
}
28+
2229
implementation(projects.compilerPluginCommon)
2330
}

compiler-plugin/compiler-plugin-cli/build.gradle.kts

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
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
import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode
6+
import util.otherwise
7+
import util.whenForIde
68

79
plugins {
810
alias(libs.plugins.conventions.jvm)
@@ -14,7 +16,12 @@ kotlin {
1416
}
1517

1618
dependencies {
17-
compileOnly(libs.kotlin.compiler.embeddable)
19+
whenForIde {
20+
compileOnly(libs.kotlin.compiler)
21+
} otherwise {
22+
compileOnly(libs.kotlin.compiler.embeddable)
23+
}
24+
1825
implementation(projects.compilerPluginK2)
1926
implementation(projects.compilerPluginCommon)
2027
implementation(projects.compilerPluginBackend)

compiler-plugin/compiler-plugin-common/build.gradle.kts

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
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
import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode
6+
import util.otherwise
7+
import util.whenForIde
68

79
plugins {
810
alias(libs.plugins.conventions.jvm)
@@ -14,5 +16,9 @@ kotlin {
1416
}
1517

1618
dependencies {
17-
compileOnly(libs.kotlin.compiler.embeddable)
19+
whenForIde {
20+
compileOnly(libs.kotlin.compiler)
21+
} otherwise {
22+
compileOnly(libs.kotlin.compiler.embeddable)
23+
}
1824
}

compiler-plugin/compiler-plugin-k2/build.gradle.kts

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ kotlin {
7272
}
7373

7474
dependencies {
75-
compileOnly(libs.kotlin.reflect)
76-
compileOnly(libs.kotlin.compiler.embeddable)
7775
whenForIde {
76+
compileOnly(libs.kotlin.compiler)
7877
compileOnly(libs.serialization.plugin.forIde) {
7978
isTransitive = false
8079
}
8180
} otherwise {
81+
compileOnly(libs.kotlin.compiler.embeddable)
8282
compileOnly(libs.serialization.plugin)
8383
}
8484
implementation(projects.compilerPluginCommon)

compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/FirRpcServiceGenerator.kt

+2-1
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
package kotlinx.rpc.codegen
@@ -11,6 +11,7 @@ import kotlinx.rpc.codegen.common.rpcMethodName
1111
import kotlinx.rpc.codegen.serialization.addAnnotation
1212
import kotlinx.rpc.codegen.serialization.generateCompanionDeclaration
1313
import kotlinx.rpc.codegen.serialization.generateSerializerImplClass
14+
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
1415
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
1516
import org.jetbrains.kotlin.descriptors.ClassKind
1617
import org.jetbrains.kotlin.descriptors.Modality

compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/FirVersionSpecificApi.kt

+2-9
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
package kotlinx.rpc.codegen
@@ -25,13 +25,6 @@ interface FirVersionSpecificApi {
2525
var FirResolvedTypeRefBuilder.coneTypeVS: ConeKotlinType
2626
}
2727

28-
val vsApiClass by lazy {
29-
runCatching {
30-
Class.forName("kotlinx.rpc.codegen.FirVersionSpecificApiImpl")
31-
}.getOrNull()
32-
}
33-
3428
inline fun <T> vsApi(body: FirVersionSpecificApi.() -> T): T {
35-
val kClass = vsApiClass?.kotlin ?: error("FirVersionSpecificApi is not present")
36-
return (kClass.objectInstance as FirVersionSpecificApi).body()
29+
return FirVersionSpecificApiImpl.body()
3730
}

compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/checkers/diagnostics/FirRpcDiagnostics.kt

+20-12
Original file line numberDiff line numberDiff line change
@@ -2,10 +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+
@file:Suppress("StructuralWrap")
6+
57
package kotlinx.rpc.codegen.checkers.diagnostics
68

79
import kotlinx.rpc.codegen.StrictModeAggregator
8-
import org.jetbrains.kotlin.com.intellij.psi.PsiElement
910
import org.jetbrains.kotlin.diagnostics.SourceElementPositioningStrategies
1011
import org.jetbrains.kotlin.diagnostics.error0
1112
import org.jetbrains.kotlin.diagnostics.error1
@@ -14,16 +15,23 @@ import org.jetbrains.kotlin.diagnostics.rendering.RootDiagnosticRendererFactory
1415
import org.jetbrains.kotlin.fir.types.ConeKotlinType
1516
import org.jetbrains.kotlin.name.Name
1617
import org.jetbrains.kotlin.psi.KtAnnotated
18+
import org.jetbrains.kotlin.psi.KtElement
19+
20+
// ###########################################################################
21+
// ### BIG WARNING, LISTEN CLOSELY! ###
22+
// # Do NOT use `PsiElement` for `error0` or any other function #
23+
// # Instead use KtElement, otherwise problems in IDE and in tests may arise #
24+
// ###########################################################################
1725

1826
object FirRpcDiagnostics {
1927
val MISSING_RPC_ANNOTATION by error0<KtAnnotated>()
2028
val MISSING_SERIALIZATION_MODULE by error0<KtAnnotated>()
2129
val WRONG_RPC_ANNOTATION_TARGET by error1<KtAnnotated, ConeKotlinType>()
2230
val CHECKED_ANNOTATION_VIOLATION by error1<KtAnnotated, ConeKotlinType>()
23-
val NON_SUSPENDING_REQUEST_WITHOUT_STREAMING_RETURN_TYPE by error0<PsiElement>()
24-
val AD_HOC_POLYMORPHISM_IN_RPC_SERVICE by error2<PsiElement, Int, Name>()
25-
val TYPE_PARAMETERS_IN_RPC_FUNCTION by error0<PsiElement>(SourceElementPositioningStrategies.TYPE_PARAMETERS_LIST)
26-
val TYPE_PARAMETERS_IN_RPC_INTERFACE by error0<PsiElement>(SourceElementPositioningStrategies.TYPE_PARAMETERS_LIST)
31+
val NON_SUSPENDING_REQUEST_WITHOUT_STREAMING_RETURN_TYPE by error0<KtElement>()
32+
val AD_HOC_POLYMORPHISM_IN_RPC_SERVICE by error2<KtElement, Int, Name>()
33+
val TYPE_PARAMETERS_IN_RPC_FUNCTION by error0<KtElement>(SourceElementPositioningStrategies.TYPE_PARAMETERS_LIST)
34+
val TYPE_PARAMETERS_IN_RPC_INTERFACE by error0<KtElement>(SourceElementPositioningStrategies.TYPE_PARAMETERS_LIST)
2735

2836
init {
2937
RootDiagnosticRendererFactory.registerFactory(RpcDiagnosticRendererFactory)
@@ -32,13 +40,13 @@ object FirRpcDiagnostics {
3240

3341
@Suppress("PropertyName", "detekt.VariableNaming")
3442
class FirRpcStrictModeDiagnostics(val modes: StrictModeAggregator) {
35-
val STATE_FLOW_IN_RPC_SERVICE by modded0<PsiElement>(modes.stateFlow)
36-
val SHARED_FLOW_IN_RPC_SERVICE by modded0<PsiElement>(modes.sharedFlow)
37-
val NESTED_STREAMING_IN_RPC_SERVICE by modded0<PsiElement>(modes.nestedFlow)
38-
val STREAM_SCOPE_FUNCTION_IN_RPC by modded0<PsiElement>(modes.streamScopedFunctions)
39-
val SUSPENDING_SERVER_STREAMING_IN_RPC_SERVICE by modded0<PsiElement>(modes.suspendingServerStreaming)
40-
val NON_TOP_LEVEL_SERVER_STREAMING_IN_RPC_SERVICE by modded0<PsiElement>(modes.notTopLevelServerFlow)
41-
val FIELD_IN_RPC_SERVICE by modded0<PsiElement>(modes.fields)
43+
val STATE_FLOW_IN_RPC_SERVICE by modded0<KtElement>(modes.stateFlow)
44+
val SHARED_FLOW_IN_RPC_SERVICE by modded0<KtElement>(modes.sharedFlow)
45+
val NESTED_STREAMING_IN_RPC_SERVICE by modded0<KtElement>(modes.nestedFlow)
46+
val STREAM_SCOPE_FUNCTION_IN_RPC by modded0<KtElement>(modes.streamScopedFunctions)
47+
val SUSPENDING_SERVER_STREAMING_IN_RPC_SERVICE by modded0<KtElement>(modes.suspendingServerStreaming)
48+
val NON_TOP_LEVEL_SERVER_STREAMING_IN_RPC_SERVICE by modded0<KtElement>(modes.notTopLevelServerFlow)
49+
val FIELD_IN_RPC_SERVICE by modded0<KtElement>(modes.fields)
4250

4351
init {
4452
RootDiagnosticRendererFactory.registerFactory(RpcStrictModeDiagnosticRendererFactory(this))

gradle-conventions-settings/build.gradle.kts

+1-2
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 {
@@ -8,7 +8,6 @@ plugins {
88

99
configurations.configureEach {
1010
resolutionStrategy {
11-
force(libs.kotlin.reflect)
1211
force(libs.kotlin.stdlib)
1312
force(libs.kotlin.stdlib.jdk7)
1413
force(libs.kotlin.stdlib.jdk8)

gradle-conventions-settings/develocity/build.gradle.kts

+1-2
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 {
@@ -8,7 +8,6 @@ plugins {
88

99
configurations.configureEach {
1010
resolutionStrategy {
11-
force(libs.kotlin.reflect)
1211
force(libs.kotlin.stdlib)
1312
force(libs.kotlin.stdlib.jdk7)
1413
force(libs.kotlin.stdlib.jdk8)
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
rootProject.name = "gradle-conventions-settings"
@@ -8,6 +8,4 @@ rootProject.name = "gradle-conventions-settings"
88
apply(from = "src/main/kotlin/conventions-repositories.settings.gradle.kts")
99
apply(from = "src/main/kotlin/conventions-version-resolution.settings.gradle.kts")
1010

11-
val kotlinVersion: KotlinVersion by extra
12-
1311
include(":develocity")

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

+16-5
Original file line numberDiff line numberDiff line change
@@ -146,25 +146,34 @@ fun resolveVersionCatalog(rootDir: Path): Map<String, String> {
146146

147147
// Uses KOTLIN_VERSION env var if present for project's Kotlin version and sets it into Version Catalog.
148148
// Otherwise uses version from catalog.
149-
fun VersionCatalogBuilder.resolveKotlinVersion(versionCatalog: Map<String, String>): String {
149+
fun VersionCatalogBuilder.resolveKotlinVersion(versionCatalog: Map<String, String>): Pair<String, String> {
150150
var kotlinCatalogVersion: String? = System.getenv(SettingsConventions.KOTLIN_VERSION_ENV_VAR_NAME)
151-
val kotlinCompilerVersion: String? = System.getenv(SettingsConventions.KOTLIN_COMPILER_VERSION_ENV_VAR_NAME)
151+
var kotlinCompilerVersion: String? = System.getenv(SettingsConventions.KOTLIN_COMPILER_VERSION_ENV_VAR_NAME)
152152

153153
if (kotlinCatalogVersion != null) {
154154
version(SettingsConventions.KOTLIN_VERSION_ALIAS, kotlinCatalogVersion)
155155
} else {
156156
kotlinCatalogVersion = versionCatalog[SettingsConventions.KOTLIN_VERSION_ALIAS]
157157
}
158158

159+
var catalogCompilerVersion = versionCatalog[SettingsConventions.KOTLIN_COMPILER_VERSION_ALIAS]
159160
if (kotlinCompilerVersion != null) {
160161
logger.info("Resolved Kotlin compiler version: $kotlinCompilerVersion")
161162
version(SettingsConventions.KOTLIN_COMPILER_VERSION_ALIAS, kotlinCompilerVersion)
163+
} else if (catalogCompilerVersion == "0.0.0") {
164+
kotlinCompilerVersion = kotlinCatalogVersion!!
165+
version(SettingsConventions.KOTLIN_COMPILER_VERSION_ALIAS, kotlinCompilerVersion)
162166
} else {
163-
version(SettingsConventions.KOTLIN_COMPILER_VERSION_ALIAS, kotlinCatalogVersion!!)
167+
kotlinCompilerVersion = catalogCompilerVersion
164168
}
165169

166-
return kotlinCatalogVersion
170+
val resolvedLang = kotlinCatalogVersion
167171
?: error("Expected to resolve '${SettingsConventions.KOTLIN_VERSION_ALIAS}' version")
172+
173+
val resolvedCompiler = kotlinCompilerVersion
174+
?: error("Expected to resolve '${SettingsConventions.KOTLIN_COMPILER_VERSION_ALIAS}' version")
175+
176+
return resolvedLang to resolvedCompiler
168177
}
169178

170179
// Resolves a core kotlinx.rpc version (without a Kotlin version prefix) from the Version Catalog.
@@ -206,7 +215,7 @@ dependencyResolutionManagement {
206215

207216
val versionCatalog = resolveVersionCatalog(rootDir)
208217

209-
val kotlinVersion = resolveKotlinVersion(versionCatalog)
218+
val (kotlinVersion, compilerVersion) = resolveKotlinVersion(versionCatalog)
210219

211220
resolveLibraryVersion(versionCatalog)
212221

@@ -216,11 +225,13 @@ dependencyResolutionManagement {
216225
val isLatestKotlin = latestKotlin == kotlinVersion
217226

218227
extra["kotlinVersion"] = kotlinVersion.kotlinVersionParsed()
228+
extra["kotlinCompilerVersion"] = compilerVersion.kotlinVersionParsed()
219229
extra["isLatestKotlinVersion"] = isLatestKotlin
220230

221231
gradle.rootProject {
222232
allprojects {
223233
this.extra["kotlinVersion"] = kotlinVersion.kotlinVersionParsed()
234+
this.extra["kotlinCompilerVersion"] = compilerVersion.kotlinVersionParsed()
224235
this.extra["isLatestKotlinVersion"] = isLatestKotlin
225236
}
226237
}

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

+1-2
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
package util
@@ -9,7 +9,6 @@ import org.gradle.api.Project
99
fun Project.defaultConventionConfiguration() {
1010
configurations.configureEach {
1111
resolutionStrategy {
12-
force(libs.kotlin.reflect)
1312
force(libs.kotlin.stdlib)
1413
force(libs.kotlin.stdlib.jdk7)
1514
force(libs.kotlin.stdlib.jdk8)

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

+5-5
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
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
@@ -8,7 +8,7 @@ import java.nio.file.Files
88
import java.nio.file.Path
99
import kotlin.text.lowercase
1010

11-
val kotlinVersion: KotlinVersion by extra
11+
val kotlinCompilerVersion: KotlinVersion by extra
1212
val preserveDefaultSourceDirectories by optionalProperty()
1313

1414
fun NamedDomainObjectContainer<KotlinSourceSet>.applyCompilerSpecificSourceSets() {
@@ -31,11 +31,11 @@ fun NamedDomainObjectContainer<KotlinSourceSet>.applyCompilerSpecificSourceSets(
3131
val vsSets = filterSourceDirsForCSM(sourceSetPath)
3232

3333
// choose 'latest' if there are no more specific ones
34-
val mostSpecificApplicable = vsSets.mostSpecificVersionOrLatest(kotlinVersion)
34+
val mostSpecificApplicable = vsSets.mostSpecificVersionOrLatest(kotlinCompilerVersion)
3535

3636
logger.lifecycle(
3737
"${project.name}: included version specific source sets: " +
38-
"[${core.name}${mostSpecificApplicable?.let { ", $name" } ?: ""}]"
38+
"[${core.name}${mostSpecificApplicable?.let { ", ${it.name}" } ?: ""}]"
3939
)
4040

4141
val newSourceDirectories = listOfNotNull(core, mostSpecificApplicable)
@@ -70,7 +70,7 @@ fun KotlinSourceSet.configureResources(sourceSetPath: Path) {
7070
}
7171

7272
val mostSpecificApplicable = filterSourceDirsForCSM(resourcesDir)
73-
.mostSpecificVersionOrLatest(kotlinVersion)
73+
.mostSpecificVersionOrLatest(kotlinCompilerVersion)
7474

7575
val versionNames = listOfNotNull(Dir.CORE_SOURCE_DIR, mostSpecificApplicable?.name)
7676

tests/compiler-plugin-tests/build.gradle.kts

+6-6
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
import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode
@@ -80,10 +80,10 @@ dependencies {
8080
testImplementation(libs.serialization.plugin)
8181
}
8282

83-
testImplementation(libs.compiler.plugin.cli) {
84-
exclude(group = "org.jetbrains.kotlinx", module = "compiler-plugin-k2")
85-
}
86-
testImplementation(files("$globalRootDir/compiler-plugin/compiler-plugin-k2/build/libs/plugin-k2-for-tests.jar"))
83+
testImplementation(libs.compiler.plugin.common)
84+
testImplementation(libs.compiler.plugin.backend)
85+
testImplementation(libs.compiler.plugin.k2)
86+
testImplementation(libs.compiler.plugin.cli)
8787

8888
testImplementation(libs.kotlin.reflect)
8989
testImplementation(libs.kotlin.compiler)
@@ -136,7 +136,7 @@ tasks.withType<KotlinCompile>().configureEach {
136136
}
137137
}
138138

139-
val generateTests by tasks.creating(JavaExec::class) {
139+
val generateTests = tasks.register<JavaExec>("generateTests") {
140140
classpath = sourceSets.test.get().runtimeClasspath
141141
mainClass.set("kotlinx.rpc.codegen.test.GenerateTestsKt")
142142
}

versions-root/libs.versions.toml

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ kover = "0.9.1"
3939
# kotlinx.rpc – references to the included builds
4040
# as they're local to the project, kotlinx-rpc- prefix is omitted
4141
compiler-plugin-cli = { module = "org.jetbrains.kotlinx:compiler-plugin-cli" }
42+
compiler-plugin-k2 = { module = "org.jetbrains.kotlinx:compiler-plugin-k2" }
43+
compiler-plugin-backend = { module = "org.jetbrains.kotlinx:compiler-plugin-backend" }
44+
compiler-plugin-common = { module = "org.jetbrains.kotlinx:compiler-plugin-common" }
4245

4346
# kotlin
4447
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin-lang" }

0 commit comments

Comments
 (0)