Skip to content

Commit 0646265

Browse files
cmelchiorSpace Team
authored andcommitted
K2 Repl Support
This MR contains all the required infrastructure to support the new K2 Repl. - It bumps Kotlin to the latest release: 2.2.0-RC2. - KSP support is removed because it is holding us back from using the latest Kotlin Compiler releases as we have to wait for releases for public versions. - The default is still K1, all unit tests for K1 are green. All unit tests are also green for K2, but running them all from the command line results in OOM errors. This is still being investigated. - For kernels running K2, the Kotlin language version is bumped from 1.9 to 2.2. - I had to bump ktlint as well, but this introduces a ton of minor changes. So, for now, I have disabled ktlint warnings, but as soon as this MR is merged. I will make a new MR where ktlint is re-enabled. Merge-request: KDS-MR-74 Merged-by: Christian Melchior <[email protected]>
1 parent 51f79db commit 0646265

File tree

99 files changed

+1946
-1032
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+1946
-1032
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[*.{kt,kts}]
22
ij_kotlin_allow_trailing_comma_on_call_site=true
33
ij_kotlin_allow_trailing_comma=true
4+
5+
[compilers.kt]
6+
ktlint_standard_filename = disabled

api-examples/getting-started/build.gradle.kts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1+
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2
12
plugins {
2-
id("com.google.devtools.ksp")
33
kotlin("jvm")
44
kotlin("jupyter.api")
55
kotlin("libs.publisher")
66
}
77

88
kotlinJupyter {
99
addApiDependency()
10-
addScannerDependency()
10+
}
11+
12+
// Creates the metadata needed for the library integration to be detected automatically.
13+
tasks.processJupyterApiResources {
14+
libraryProducers = listOf("org.jetbrains.kotlinx.jupyter.example.GettingStartedIntegration")
15+
}
16+
17+
kotlin {
18+
compilerOptions {
19+
apiVersion.set(KOTLIN_2_2)
20+
languageVersion.set(KOTLIN_2_2)
21+
}
1122
}
1223

1324
dependencies {

api-examples/getting-started/src/main/kotlin/org/jetbrains/kotlinx/jupyter/example/GettingStartedIntegration.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package org.jetbrains.kotlinx.jupyter.example
22

33
import org.jetbrains.kotlinx.jupyter.api.FieldHandlerByRuntimeClass
4-
import org.jetbrains.kotlinx.jupyter.api.annotations.JupyterLibrary
54
import org.jetbrains.kotlinx.jupyter.api.libraries.JupyterIntegration
65

7-
@JupyterLibrary
86
class GettingStartedIntegration : JupyterIntegration() {
97
override fun Builder.onLoaded() {
108
/**

build-plugin/build.gradle.kts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
12
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
23

34
plugins {
@@ -29,9 +30,14 @@ val myJvmTarget = libs.versions.jvmTarget.get()
2930
val myJvmTargetInt = myJvmTarget.substringAfter('.').toInt()
3031

3132
tasks.withType<KotlinCompile> {
32-
kotlinOptions {
33-
freeCompilerArgs = freeCompilerArgs + listOf("-opt-in=kotlin.RequiresOptIn")
34-
jvmTarget = myJvmTarget
33+
compilerOptions {
34+
freeCompilerArgs.addAll(listOf(
35+
"-opt-in=kotlin.RequiresOptIn",
36+
// Fix for https://jakewharton.com/kotlins-jdk-release-compatibility-flag/
37+
// See https://youtrack.jetbrains.com/issue/KT-49746/Support-Xjdk-release-in-gradle-toolchain#focus=Comments-27-9473530.0-0
38+
"-Xjdk-release=$myJvmTarget"
39+
))
40+
jvmTarget.set(JvmTarget.fromTarget(myJvmTarget))
3541
}
3642
}
3743

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
2+
13
plugins {
24
kotlin("libs.publisher")
35
kotlin("jvm")
@@ -25,14 +27,12 @@ sourceSets {
2527
val myJvmTarget = libs.versions.jvmTarget.get()
2628
val myJvmTargetInt = myJvmTarget.substringAfter('.').toInt()
2729

28-
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
29-
kotlinOptions {
30-
apiVersion = "1.4"
31-
languageVersion = "1.4"
32-
33-
freeCompilerArgs += listOf("-opt-in=kotlin.RequiresOptIn")
34-
35-
this.jvmTarget = myJvmTarget
30+
kotlin {
31+
compilerOptions {
32+
apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2)
33+
languageVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2)
34+
freeCompilerArgs.add("-opt-in=kotlin.RequiresOptIn")
35+
this.jvmTarget.set(JvmTarget.fromTarget(myJvmTarget))
3636
}
3737
}
3838

build-plugin/common-dependencies/src/org/jetbrains/kotlinx/jupyter/common/ReplLineMagic.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
package org.jetbrains.kotlinx.jupyter.common
22

3+
/**
4+
* This class defines the magic commands available to users of a notebook. They are accessed
5+
* by using the `%<enumNameInCamelCase>` syntax inside a notebook.
6+
*
7+
* Example:
8+
*
9+
* ```
10+
* // Snippet 1
11+
* %useLatestDescriptors
12+
* println("Hello world")
13+
* ```
14+
*
15+
* Adding a new magic value also requires registering a handler in [org.jetbrains.kotlinx.jupyter.magics.AbstractMagicsHandler].
16+
*/
317
enum class ReplLineMagic(val desc: String, val argumentsUsage: String? = null, val visibleInHelp: Boolean = true) {
418
USE(
519
"Imports supported libraries and injects code from these libraries" +

build-plugin/plugin-versions-plugin/settings.gradle.kts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33
rootProject.name = "plugin-versions"
44

55
pluginManagement {
6+
val sharedProps = java.util.Properties().apply {
7+
load(File(rootDir.parentFile.parent, "shared.properties").inputStream())
8+
}
69
repositories {
710
mavenCentral()
811
gradlePluginPortal()
12+
// Artifacts here are guaranteed to not be removed, unlike https://packages.jetbrains.team/maven/p/kt/dev.
13+
// But note that /kt/dev is updated faster.
14+
maven(sharedProps.getProperty("kotlin.repository"))
915
if (System.getenv("KOTLIN_JUPYTER_USE_MAVEN_LOCAL") != null) {
1016
mavenLocal()
1117
}
@@ -17,6 +23,9 @@ plugins {
1723
}
1824

1925
dependencyResolutionManagement {
26+
val sharedProps = java.util.Properties().apply {
27+
load(File(rootDir.parentFile.parent, "shared.properties").inputStream())
28+
}
2029
versionCatalogs {
2130
create("libs") {
2231
from(files("../../gradle/libs.versions.toml"))
@@ -25,6 +34,7 @@ dependencyResolutionManagement {
2534
repositories {
2635
mavenCentral()
2736
gradlePluginPortal()
37+
maven(sharedProps.getProperty("kotlin.repository"))
2838
if (System.getenv("KOTLIN_JUPYTER_USE_MAVEN_LOCAL") != null) {
2939
mavenLocal()
3040
}

build-plugin/settings.gradle.kts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
@file:Suppress("UnstableApiUsage")
22

3-
import org.gradle.kotlin.dsl.mavenCentral
4-
import org.gradle.kotlin.dsl.repositories
5-
63
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
74

85
rootProject.name = "build"
96

107
pluginManagement {
118
repositories {
9+
val sharedProps = java.util.Properties().apply {
10+
load(File(rootDir.parent, "shared.properties").inputStream())
11+
}
1212
mavenCentral()
1313
gradlePluginPortal()
14+
maven(sharedProps.getProperty("kotlin.repository"))
15+
maven(sharedProps.getProperty("kotlin.ds.repository"))
1416
if (System.getenv("KOTLIN_JUPYTER_USE_MAVEN_LOCAL") != null) {
1517
mavenLocal()
1618
}
@@ -22,6 +24,9 @@ plugins {
2224
}
2325

2426
dependencyResolutionManagement {
27+
val sharedProps = java.util.Properties().apply {
28+
load(File(rootDir.parent, "shared.properties").inputStream())
29+
}
2530
versionCatalogs {
2631
create("libs") {
2732
from(files("../gradle/libs.versions.toml"))
@@ -30,7 +35,8 @@ dependencyResolutionManagement {
3035
repositories {
3136
mavenCentral()
3237
gradlePluginPortal()
33-
maven("https://packages.jetbrains.team/maven/p/kds/kotlin-ds-maven")
38+
maven(sharedProps.getProperty("kotlin.repository"))
39+
maven(sharedProps.getProperty("kotlin.ds.repository"))
3440
if (System.getenv("KOTLIN_JUPYTER_USE_MAVEN_LOCAL") != null) {
3541
mavenLocal()
3642
}

build-plugin/src/build/BuildSettingsExtension.kt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import org.gradle.api.tasks.compile.JavaCompile
1212
import org.gradle.api.tasks.testing.Test
1313
import org.gradle.kotlin.dsl.dependencies
1414
import org.gradle.kotlin.dsl.withType
15+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
16+
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
1517
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
1618

1719
class BuildSettingsExtension(private val project: Project) {
@@ -39,18 +41,21 @@ class BuildSettingsExtension(private val project: Project) {
3941
withApiVersion(level)
4042
}
4143

44+
4245
fun withLanguageVersion(version: String) {
46+
val kotlinVersion = KotlinVersion.fromVersion(version)
4347
project.tasks.withType<KotlinCompile> {
44-
kotlinOptions {
45-
languageVersion = version
48+
compilerOptions {
49+
languageVersion.set(kotlinVersion)
4650
}
4751
}
4852
}
4953

5054
fun withApiVersion(version: String) {
55+
val kotlinVersion = KotlinVersion.fromVersion(version)
5156
project.tasks.withType<KotlinCompile> {
52-
kotlinOptions {
53-
apiVersion = version
57+
compilerOptions {
58+
apiVersion.set(kotlinVersion)
5459
}
5560
}
5661
}
@@ -74,16 +79,16 @@ class BuildSettingsExtension(private val project: Project) {
7479
fun withCompilerArgs(configure: KotlinCompilerArgsBuilder.() -> Unit) {
7580
val argsList = KotlinCompilerArgsBuilder().apply(configure).build()
7681
project.tasks.withType<KotlinCompile> {
77-
kotlinOptions {
78-
freeCompilerArgs += argsList
82+
compilerOptions {
83+
freeCompilerArgs.addAll(argsList)
7984
}
8085
}
8186
}
8287

8388
fun withJvmTarget(target: String) {
8489
project.tasks.withType<KotlinCompile> {
85-
kotlinOptions {
86-
this.jvmTarget = target
90+
compilerOptions {
91+
jvmTarget.set(JvmTarget.fromTarget(target))
8792
}
8893
}
8994

build-plugin/src/build/KernelBuildConfigurator.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ internal class KernelBuildConfigurator(private val project: Project) {
9797
plugins.apply("org.jlleitschuh.gradle.ktlint")
9898
extensions.configure<KtlintExtension> {
9999
version.set(ktlintVersion)
100+
// TEMPORARY CHANGE: Until K2 REPL has been merged to master to avoid too many changes at once.
101+
ignoreFailures.set(true)
100102
enableExperimentalRules.set(true)
101103
}
102104
}

build-plugin/src/build/RootSettingsExtension.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@ class RootSettingsExtension(
8282
CompatibilityAttribute("kotlinLanguageLevel", "Kotlin language level") {
8383
kotlinLanguageLevel
8484
},
85-
CompatibilityAttribute("kspVersion", "KSP") {
86-
projectVersions.ksp
87-
},
8885
)
8986
}
9087

build-plugin/src/build/util/repositories.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ package build.util
33
import org.gradle.api.Project
44
import org.gradle.kotlin.dsl.maven
55
import org.gradle.kotlin.dsl.repositories
6+
import java.io.File
67

78
const val INTERNAL_TEAMCITY_URL = "https://buildserver.labs.intellij.net"
89
const val PUBLIC_TEAMCITY_URL = "https://teamcity.jetbrains.com"
910

1011
class TeamcityProject(
1112
val url: String,
12-
val projectId: String
13+
val projectId: String,
1314
)
1415

1516
val INTERNAL_KOTLIN_TEAMCITY = TeamcityProject(INTERNAL_TEAMCITY_URL, "Kotlin_KotlinDev_Artifacts")
@@ -20,12 +21,14 @@ const val TEAMCITY_REQUEST_ENDPOINT = "guestAuth/app/rest/builds"
2021
fun Project.addAllBuildRepositories() {
2122
val kotlinVersion = rootProject.defaultVersionCatalog.versions.devKotlin
2223

24+
val sharedProps = java.util.Properties().apply {
25+
load(File(rootDir, "shared.properties").inputStream())
26+
}
27+
2328
repositories {
2429
mavenCentral()
2530
gradlePluginPortal()
26-
27-
// Kotlin Dev releases are published here every night
28-
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev")
31+
maven(sharedProps.getProperty("kotlin.repository"))
2932

3033
for (teamcity in listOf(INTERNAL_KOTLIN_TEAMCITY, PUBLIC_KOTLIN_TEAMCITY)) {
3134
val locator = "buildType:(id:${teamcity.projectId}),number:$kotlinVersion,branch:default:any/artifacts/content/maven"

build.gradle.kts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import org.jetbrains.kotlinx.publisher.apache2
1313
import org.jetbrains.kotlinx.publisher.composeOfTaskOutputs
1414
import org.jetbrains.kotlinx.publisher.developer
1515
import org.jetbrains.kotlinx.publisher.githubRepo
16+
import java.util.Properties
1617

1718
plugins {
1819
id("build.plugins.main")
@@ -29,12 +30,37 @@ val spaceUsername: String by properties
2930
val spaceToken: String by properties
3031

3132
ktlint {
33+
version.set(libs.versions.ktlint.get())
34+
// TEMPORARY CHANGE: Until K2 REPL has been merged to master to avoid too many changes at once.
35+
ignoreFailures.set(true)
3236
filter {
3337
exclude("**/org/jetbrains/kotlinx/jupyter/repl.kt")
3438
}
3539
}
3640

41+
val sharedProps =
42+
Properties().apply {
43+
load(File(rootDir, "shared.properties").inputStream())
44+
}
45+
46+
repositories {
47+
mavenCentral()
48+
maven(sharedProps.getProperty("kotlin.repository"))
49+
maven(sharedProps.getProperty("kotlin.ds.repository"))
50+
maven {
51+
name = "intellij-deps"
52+
url = uri("https://www.jetbrains.com/intellij-repository/releases/")
53+
}
54+
if (System.getenv("KOTLIN_JUPYTER_USE_MAVEN_LOCAL") != null) {
55+
mavenLocal()
56+
}
57+
}
58+
3759
dependencies {
60+
// Required by K2KJvmReplCompilerWithCompletion.
61+
// Should be moved to Kotlin Compiler eventually once complete
62+
compileOnly("com.jetbrains.intellij.platform:util:243.22562.220")
63+
3864
implementation(libs.kotlin.dev.stdlib)
3965

4066
// Dependency on module with compiler.
@@ -71,6 +97,8 @@ dependencies {
7197
// Test dependencies: kotlin-test and Junit 5
7298
testImplementation(libs.test.junit.params)
7399
testImplementation(libs.test.kotlintest.assertions)
100+
testImplementation(libs.kotlin.dev.scriptingDependenciesMavenAll)
101+
74102

75103
deploy(projects.lib)
76104
deploy(projects.api)

docs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
# Kotlin Kernel for Jupyter notebooks
1111

12-
The Kotlin Kernel for Jupyter notebooks is a powerful tool that allows you to write and run [Kotlin](https://kotlinlang.org/) 1.9.23 code within the
12+
The Kotlin Kernel for Jupyter notebooks is a powerful tool that allows you to write and run [Kotlin](https://kotlinlang.org/) 2.2.0-RC2 code within the
1313
[Jupyter Notebook](https://jupyter.org) environment. This [Kernel](https://docs.jupyter.org/en/latest/projects/kernels.html) essentially acts as a bridge between Jupyter Notebook and the Kotlin compiler.
1414

1515
<img src="images/kotlin_notebook.gif" width="900" height="700" alt="Alt text for the GIF">
@@ -90,7 +90,7 @@ Start using the Kotlin Kernel for Jupyter notebooks:
9090
9191
### Kotlin version support
9292

93-
The latest version of the Kotlin Kernel for notebooks uses the Kotlin compiler of version 1.9.23.
93+
The latest version of the Kotlin Kernel for notebooks uses the Kotlin compiler of version 2.2.0-RC2.
9494

9595
### Jupyter environments
9696

0 commit comments

Comments
 (0)