Skip to content

Added Kotlin for ide configs to project #219

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
Nov 4, 2024
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
10 changes: 9 additions & 1 deletion compiler-plugin/compiler-plugin-k2/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

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

plugins {
alias(libs.plugins.conventions.jvm)
Expand All @@ -19,6 +21,12 @@ kotlin {
dependencies {
compileOnly(libs.kotlin.reflect)
compileOnly(libs.kotlin.compiler.embeddable)
compileOnly(libs.serialization.plugin)
whenForIde {
compileOnly(libs.serialization.plugin.forIde) {
isTransitive = false
}
} otherwise {
compileOnly(libs.serialization.plugin)
}
implementation(projects.compilerPluginCommon)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ fun Path.bufferedReader(

object SettingsConventions {
const val KOTLIN_VERSION_ENV_VAR_NAME = "KOTLIN_VERSION"
const val KOTLIN_COMPILER_VERSION_ENV_VAR_NAME = "KOTLIN_COMPILER_VERSION"
const val LIBRARY_VERSION_ENV_VAR_NAME = "LIBRARY_VERSION"
const val EAP_VERSION_ENV_VAR_NAME = "EAP_VERSION"

const val LIBRARY_CORE_VERSION_ALIAS = "kotlinx-rpc"
const val KOTLIN_VERSION_ALIAS = "kotlin-lang"
const val KOTLIN_COMPILER_VERSION_ALIAS = "kotlin-compiler"

const val VERSIONS_SECTION_NAME = "[versions]"

Expand Down Expand Up @@ -146,13 +148,20 @@ fun resolveVersionCatalog(rootDir: Path): Map<String, String> {
// Otherwise uses version from catalog.
fun VersionCatalogBuilder.resolveKotlinVersion(versionCatalog: Map<String, 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)

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

if (kotlinCompilerVersion != null) {
version(SettingsConventions.KOTLIN_COMPILER_VERSION_ALIAS, kotlinCompilerVersion)
} else {
version(SettingsConventions.KOTLIN_COMPILER_VERSION_ALIAS, kotlinCatalogVersion!!)
}

return kotlinCatalogVersion
?: error("Expected to resolve '${SettingsConventions.KOTLIN_VERSION_ALIAS}' version")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fun ProjectKotlinConfig.configureJs() {
return
}

kotlin {
kmp {
js(IR) {
configureJsAndWasmJsTasks()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.gradle.kotlin.dsl.the
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension

fun Project.kotlin(block: KotlinMultiplatformExtension.() -> Unit) {
fun Project.kmp(block: KotlinMultiplatformExtension.() -> Unit) {
configure(block)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private fun Project.configureDetekt(targets: List<KotlinTarget>) {
}

fun ProjectKotlinConfig.configureKotlin(action: Action<KotlinMultiplatformExtension> = Action { }) {
kotlin {
kmp {
val includedTargets = configureTargets(this@configureKotlin)

configureDetekt(includedTargets)
Expand Down
17 changes: 17 additions & 0 deletions gradle-conventions-settings/src/main/kotlin/util/forIde.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package util

import org.gradle.api.Project

fun Project.whenForIde(block: () -> Unit): ActionApplied {
val forIdeBuild by optionalProperty()

if (forIdeBuild) {
block()
}

return ActionApplied(forIdeBuild)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ fun PublishingExtension.configurePublication() {
repositories {
configureSonatypeRepository()
configureSpaceRepository()
configureForIdeRepository()
configureLocalDevRepository()
}

Expand Down Expand Up @@ -118,6 +119,15 @@ fun RepositoryHandler.configureSpaceRepository() {
}
}

fun RepositoryHandler.configureForIdeRepository() {
configureRepository(project) {
username = "SPACE_USERNAME"
password = "SPACE_PASSWORD"
name = "forIde"
url = "https://maven.pkg.jetbrains.space/public/p/krpc/for-ide"
}
}

fun RepositoryHandler.configureLocalDevRepository() {
// Something that's straightforward to "clean" for development, not mavenLocal
maven("$globalRootDir/build/repo") {
Expand Down
2 changes: 1 addition & 1 deletion gradle-conventions/src/main/latest/util/wasm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fun ProjectKotlinConfig.configureWasm() {
}
}

kotlin {
kmp {
if (wasmJs) {
wasmJs {
configureJsAndWasmJsTasks()
Expand Down
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ kotlin.suppressGradlePluginWarnings=IncorrectCompileOnlyDependencyWarning
# Uncomment to skip adding git tags to Develocity build scan
# Add this property to ~/.gradle/gradle.properties to avoid polluting git with unwanted changes
#kotlinx.rpc.develocity.skipGitTags=true

# set to true when building IDE compiler plugin artifacts
kotlinx.rpc.forIdeBuild=false
11 changes: 10 additions & 1 deletion tests/compiler-plugin-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

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

plugins {
java
Expand Down Expand Up @@ -69,7 +71,14 @@ dependencies {
testRuntimeOnly(libs.kotlin.script.runtime)
testRuntimeOnly(libs.kotlin.annotations.jvm)

testImplementation(libs.serialization.plugin)
whenForIde {
testImplementation(libs.serialization.plugin.forIde) {
isTransitive = false
}
} otherwise {
testImplementation(libs.serialization.plugin)
}

testImplementation(libs.compiler.plugin.cli)

testImplementation(libs.kotlin.reflect)
Expand Down
8 changes: 5 additions & 3 deletions versions-root/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
kotlinx-rpc = "0.3.0"

# kotlin
kotlin-lang = "2.0.21"
kotlin-lang = "2.0.21" # or env.KOTLIN_VERSION
kotlin-compiler = "0.0.0" # default to kotlin-lang or env.KOTLIN_COMPILER_VERSION

# kotlin independent versions
detekt-analyzer = "1.23.6"
Expand Down Expand Up @@ -49,10 +50,11 @@ kotlin-script-runtime = { module = "org.jetbrains.kotlin:kotlin-script-runtime",
kotlin-annotations-jvm = { module = "org.jetbrains.kotlin:kotlin-annotations-jvm", version.ref = "kotlin-lang" }
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin-lang" }

kotlin-compiler = { module = "org.jetbrains.kotlin:kotlin-compiler", version.ref = "kotlin-lang" }
kotlin-compiler = { module = "org.jetbrains.kotlin:kotlin-compiler", version.ref = "kotlin-compiler" }
kotlin-compiler-embeddable = { module = "org.jetbrains.kotlin:kotlin-compiler-embeddable" }
kotlin-compiler-test-framework = { module = "org.jetbrains.kotlin:kotlin-compiler-internal-test-framework", version.ref = "kotlin-lang" }
serialization-plugin = { module = "org.jetbrains.kotlin:kotlin-serialization-compiler-plugin", version.ref = "kotlin-lang" }
serialization-plugin = { module = "org.jetbrains.kotlin:kotlin-serialization-compiler-plugin", version.ref = "kotlin-compiler" }
serialization-plugin-forIde = { module = "org.jetbrains.kotlin:kotlinx-serialization-compiler-plugin-for-ide", version.ref = "kotlin-compiler" }
kotlinx-browser = { module = "org.jetbrains.kotlinx:kotlinx-browser", version.ref = "kotlinx-browser" }

# serialization
Expand Down