Skip to content

Fix build config for for-ide builds #287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions compiler-plugin/compiler-plugin-backend/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode
import util.otherwise
import util.whenForIde

plugins {
alias(libs.plugins.conventions.jvm)
Expand All @@ -18,6 +20,11 @@ kotlin {
}

dependencies {
compileOnly(libs.kotlin.compiler.embeddable)
whenForIde {
compileOnly(libs.kotlin.compiler)
} otherwise {
compileOnly(libs.kotlin.compiler.embeddable)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dependency has been deprecated in the kgp. Could you tell me if we can be more specific here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

embeddable is the proper dependency for compiler plugins, as embeddable runs during compilation process. Now, raw compiler runs in IDE, hence the difference

}

implementation(projects.compilerPluginCommon)
}
11 changes: 9 additions & 2 deletions compiler-plugin/compiler-plugin-cli/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode
import util.otherwise
import util.whenForIde

plugins {
alias(libs.plugins.conventions.jvm)
Expand All @@ -14,7 +16,12 @@ kotlin {
}

dependencies {
compileOnly(libs.kotlin.compiler.embeddable)
whenForIde {
compileOnly(libs.kotlin.compiler)
} otherwise {
compileOnly(libs.kotlin.compiler.embeddable)
}

implementation(projects.compilerPluginK2)
implementation(projects.compilerPluginCommon)
implementation(projects.compilerPluginBackend)
Expand Down
10 changes: 8 additions & 2 deletions compiler-plugin/compiler-plugin-common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode
import util.otherwise
import util.whenForIde

plugins {
alias(libs.plugins.conventions.jvm)
Expand All @@ -14,5 +16,9 @@ kotlin {
}

dependencies {
compileOnly(libs.kotlin.compiler.embeddable)
whenForIde {
compileOnly(libs.kotlin.compiler)
} otherwise {
compileOnly(libs.kotlin.compiler.embeddable)
}
}
4 changes: 2 additions & 2 deletions compiler-plugin/compiler-plugin-k2/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ kotlin {
}

dependencies {
compileOnly(libs.kotlin.reflect)
compileOnly(libs.kotlin.compiler.embeddable)
whenForIde {
compileOnly(libs.kotlin.compiler)
compileOnly(libs.serialization.plugin.forIde) {
isTransitive = false
}
} otherwise {
compileOnly(libs.kotlin.compiler.embeddable)
compileOnly(libs.serialization.plugin)
}
implementation(projects.compilerPluginCommon)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.rpc.codegen
Expand All @@ -11,6 +11,7 @@ import kotlinx.rpc.codegen.common.rpcMethodName
import kotlinx.rpc.codegen.serialization.addAnnotation
import kotlinx.rpc.codegen.serialization.generateCompanionDeclaration
import kotlinx.rpc.codegen.serialization.generateSerializerImplClass
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.Modality
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.rpc.codegen
Expand All @@ -25,13 +25,6 @@ interface FirVersionSpecificApi {
var FirResolvedTypeRefBuilder.coneTypeVS: ConeKotlinType
}

val vsApiClass by lazy {
runCatching {
Class.forName("kotlinx.rpc.codegen.FirVersionSpecificApiImpl")
}.getOrNull()
}

inline fun <T> vsApi(body: FirVersionSpecificApi.() -> T): T {
val kClass = vsApiClass?.kotlin ?: error("FirVersionSpecificApi is not present")
return (kClass.objectInstance as FirVersionSpecificApi).body()
return FirVersionSpecificApiImpl.body()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

@file:Suppress("StructuralWrap")

package kotlinx.rpc.codegen.checkers.diagnostics

import kotlinx.rpc.codegen.StrictModeAggregator
import org.jetbrains.kotlin.com.intellij.psi.PsiElement
import org.jetbrains.kotlin.diagnostics.SourceElementPositioningStrategies
import org.jetbrains.kotlin.diagnostics.error0
import org.jetbrains.kotlin.diagnostics.error1
Expand All @@ -14,16 +15,23 @@ import org.jetbrains.kotlin.diagnostics.rendering.RootDiagnosticRendererFactory
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.KtAnnotated
import org.jetbrains.kotlin.psi.KtElement

// ###########################################################################
// ### BIG WARNING, LISTEN CLOSELY! ###
// # Do NOT use `PsiElement` for `error0` or any other function #
// # Instead use KtElement, otherwise problems in IDE and in tests may arise #
// ###########################################################################

object FirRpcDiagnostics {
val MISSING_RPC_ANNOTATION by error0<KtAnnotated>()
val MISSING_SERIALIZATION_MODULE by error0<KtAnnotated>()
val WRONG_RPC_ANNOTATION_TARGET by error1<KtAnnotated, ConeKotlinType>()
val CHECKED_ANNOTATION_VIOLATION by error1<KtAnnotated, ConeKotlinType>()
val NON_SUSPENDING_REQUEST_WITHOUT_STREAMING_RETURN_TYPE by error0<PsiElement>()
val AD_HOC_POLYMORPHISM_IN_RPC_SERVICE by error2<PsiElement, Int, Name>()
val TYPE_PARAMETERS_IN_RPC_FUNCTION by error0<PsiElement>(SourceElementPositioningStrategies.TYPE_PARAMETERS_LIST)
val TYPE_PARAMETERS_IN_RPC_INTERFACE by error0<PsiElement>(SourceElementPositioningStrategies.TYPE_PARAMETERS_LIST)
val NON_SUSPENDING_REQUEST_WITHOUT_STREAMING_RETURN_TYPE by error0<KtElement>()
val AD_HOC_POLYMORPHISM_IN_RPC_SERVICE by error2<KtElement, Int, Name>()
val TYPE_PARAMETERS_IN_RPC_FUNCTION by error0<KtElement>(SourceElementPositioningStrategies.TYPE_PARAMETERS_LIST)
val TYPE_PARAMETERS_IN_RPC_INTERFACE by error0<KtElement>(SourceElementPositioningStrategies.TYPE_PARAMETERS_LIST)

init {
RootDiagnosticRendererFactory.registerFactory(RpcDiagnosticRendererFactory)
Expand All @@ -32,13 +40,13 @@ object FirRpcDiagnostics {

@Suppress("PropertyName", "detekt.VariableNaming")
class FirRpcStrictModeDiagnostics(val modes: StrictModeAggregator) {
val STATE_FLOW_IN_RPC_SERVICE by modded0<PsiElement>(modes.stateFlow)
val SHARED_FLOW_IN_RPC_SERVICE by modded0<PsiElement>(modes.sharedFlow)
val NESTED_STREAMING_IN_RPC_SERVICE by modded0<PsiElement>(modes.nestedFlow)
val STREAM_SCOPE_FUNCTION_IN_RPC by modded0<PsiElement>(modes.streamScopedFunctions)
val SUSPENDING_SERVER_STREAMING_IN_RPC_SERVICE by modded0<PsiElement>(modes.suspendingServerStreaming)
val NON_TOP_LEVEL_SERVER_STREAMING_IN_RPC_SERVICE by modded0<PsiElement>(modes.notTopLevelServerFlow)
val FIELD_IN_RPC_SERVICE by modded0<PsiElement>(modes.fields)
val STATE_FLOW_IN_RPC_SERVICE by modded0<KtElement>(modes.stateFlow)
val SHARED_FLOW_IN_RPC_SERVICE by modded0<KtElement>(modes.sharedFlow)
val NESTED_STREAMING_IN_RPC_SERVICE by modded0<KtElement>(modes.nestedFlow)
val STREAM_SCOPE_FUNCTION_IN_RPC by modded0<KtElement>(modes.streamScopedFunctions)
val SUSPENDING_SERVER_STREAMING_IN_RPC_SERVICE by modded0<KtElement>(modes.suspendingServerStreaming)
val NON_TOP_LEVEL_SERVER_STREAMING_IN_RPC_SERVICE by modded0<KtElement>(modes.notTopLevelServerFlow)
val FIELD_IN_RPC_SERVICE by modded0<KtElement>(modes.fields)

init {
RootDiagnosticRendererFactory.registerFactory(RpcStrictModeDiagnosticRendererFactory(this))
Expand Down
3 changes: 1 addition & 2 deletions gradle-conventions-settings/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

plugins {
Expand All @@ -8,7 +8,6 @@ plugins {

configurations.configureEach {
resolutionStrategy {
force(libs.kotlin.reflect)
force(libs.kotlin.stdlib)
force(libs.kotlin.stdlib.jdk7)
force(libs.kotlin.stdlib.jdk8)
Expand Down
3 changes: 1 addition & 2 deletions gradle-conventions-settings/develocity/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

plugins {
Expand All @@ -8,7 +8,6 @@ plugins {

configurations.configureEach {
resolutionStrategy {
force(libs.kotlin.reflect)
force(libs.kotlin.stdlib)
force(libs.kotlin.stdlib.jdk7)
force(libs.kotlin.stdlib.jdk8)
Expand Down
4 changes: 1 addition & 3 deletions gradle-conventions-settings/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

rootProject.name = "gradle-conventions-settings"
Expand All @@ -8,6 +8,4 @@ rootProject.name = "gradle-conventions-settings"
apply(from = "src/main/kotlin/conventions-repositories.settings.gradle.kts")
apply(from = "src/main/kotlin/conventions-version-resolution.settings.gradle.kts")

val kotlinVersion: KotlinVersion by extra

include(":develocity")
Original file line number Diff line number Diff line change
Expand Up @@ -146,25 +146,34 @@ fun resolveVersionCatalog(rootDir: Path): Map<String, String> {

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

if (kotlinCatalogVersion != null) {
version(SettingsConventions.KOTLIN_VERSION_ALIAS, kotlinCatalogVersion)
} else {
kotlinCatalogVersion = versionCatalog[SettingsConventions.KOTLIN_VERSION_ALIAS]
}

var catalogCompilerVersion = versionCatalog[SettingsConventions.KOTLIN_COMPILER_VERSION_ALIAS]
if (kotlinCompilerVersion != null) {
logger.info("Resolved Kotlin compiler version: $kotlinCompilerVersion")
version(SettingsConventions.KOTLIN_COMPILER_VERSION_ALIAS, kotlinCompilerVersion)
} else if (catalogCompilerVersion == "0.0.0") {
kotlinCompilerVersion = kotlinCatalogVersion!!
version(SettingsConventions.KOTLIN_COMPILER_VERSION_ALIAS, kotlinCompilerVersion)
} else {
version(SettingsConventions.KOTLIN_COMPILER_VERSION_ALIAS, kotlinCatalogVersion!!)
kotlinCompilerVersion = catalogCompilerVersion
}

return kotlinCatalogVersion
val resolvedLang = kotlinCatalogVersion
?: error("Expected to resolve '${SettingsConventions.KOTLIN_VERSION_ALIAS}' version")

val resolvedCompiler = kotlinCompilerVersion
?: error("Expected to resolve '${SettingsConventions.KOTLIN_COMPILER_VERSION_ALIAS}' version")

return resolvedLang to resolvedCompiler
}

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

val versionCatalog = resolveVersionCatalog(rootDir)

val kotlinVersion = resolveKotlinVersion(versionCatalog)
val (kotlinVersion, compilerVersion) = resolveKotlinVersion(versionCatalog)

resolveLibraryVersion(versionCatalog)

Expand All @@ -216,11 +225,13 @@ dependencyResolutionManagement {
val isLatestKotlin = latestKotlin == kotlinVersion

extra["kotlinVersion"] = kotlinVersion.kotlinVersionParsed()
extra["kotlinCompilerVersion"] = compilerVersion.kotlinVersionParsed()
extra["isLatestKotlinVersion"] = isLatestKotlin

gradle.rootProject {
allprojects {
this.extra["kotlinVersion"] = kotlinVersion.kotlinVersionParsed()
this.extra["kotlinCompilerVersion"] = compilerVersion.kotlinVersionParsed()
this.extra["isLatestKotlinVersion"] = isLatestKotlin
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package util
Expand All @@ -9,7 +9,6 @@ import org.gradle.api.Project
fun Project.defaultConventionConfiguration() {
configurations.configureEach {
resolutionStrategy {
force(libs.kotlin.reflect)
force(libs.kotlin.stdlib)
force(libs.kotlin.stdlib.jdk7)
force(libs.kotlin.stdlib.jdk8)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
Expand All @@ -8,7 +8,7 @@ import java.nio.file.Files
import java.nio.file.Path
import kotlin.text.lowercase

val kotlinVersion: KotlinVersion by extra
val kotlinCompilerVersion: KotlinVersion by extra
val preserveDefaultSourceDirectories by optionalProperty()

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

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

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

val newSourceDirectories = listOfNotNull(core, mostSpecificApplicable)
Expand Down Expand Up @@ -70,7 +70,7 @@ fun KotlinSourceSet.configureResources(sourceSetPath: Path) {
}

val mostSpecificApplicable = filterSourceDirsForCSM(resourcesDir)
.mostSpecificVersionOrLatest(kotlinVersion)
.mostSpecificVersionOrLatest(kotlinCompilerVersion)

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

Expand Down
12 changes: 6 additions & 6 deletions tests/compiler-plugin-tests/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode
Expand Down Expand Up @@ -80,10 +80,10 @@ dependencies {
testImplementation(libs.serialization.plugin)
}

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

testImplementation(libs.kotlin.reflect)
testImplementation(libs.kotlin.compiler)
Expand Down Expand Up @@ -136,7 +136,7 @@ tasks.withType<KotlinCompile>().configureEach {
}
}

val generateTests by tasks.creating(JavaExec::class) {
val generateTests = tasks.register<JavaExec>("generateTests") {
classpath = sourceSets.test.get().runtimeClasspath
mainClass.set("kotlinx.rpc.codegen.test.GenerateTestsKt")
}
Expand Down
3 changes: 3 additions & 0 deletions versions-root/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ kover = "0.9.1"
# kotlinx.rpc – references to the included builds
# as they're local to the project, kotlinx-rpc- prefix is omitted
compiler-plugin-cli = { module = "org.jetbrains.kotlinx:compiler-plugin-cli" }
compiler-plugin-k2 = { module = "org.jetbrains.kotlinx:compiler-plugin-k2" }
compiler-plugin-backend = { module = "org.jetbrains.kotlinx:compiler-plugin-backend" }
compiler-plugin-common = { module = "org.jetbrains.kotlinx:compiler-plugin-common" }

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