Skip to content

Commit b02cc91

Browse files
authored
feat: Kotlin 2.1.20-Beta2 release (#4680)
1 parent 144f5dc commit b02cc91

File tree

4 files changed

+179
-8
lines changed

4 files changed

+179
-8
lines changed

docs/kr.tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
</toc-element>
2525
<toc-element toc-title="What's new in Kotlin">
2626
<toc-element toc-title="Kotlin 2.1.0" accepts-web-file-names="whatsnew.html" topic="whatsnew21.md"/>
27-
<toc-element toc-title="Kotlin 2.1.20-Beta1" topic="whatsnew-eap.md"/>
27+
<toc-element toc-title="Kotlin 2.1.20-Beta2" topic="whatsnew-eap.md"/>
2828
<toc-element toc-title="Earlier versions">
2929
<toc-element toc-title="Kotlin 2.0.20" topic="whatsnew2020.md"/>
3030
<toc-element toc-title="Kotlin 2.0.0" topic="whatsnew20.md"/>

docs/topics/eap.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ In this channel, you can also get notifications about new EAP builds.
4343
<th>Build highlights</th>
4444
</tr>
4545
<tr>
46-
<td><strong>2.1.20-Beta1</strong>
47-
<p>Released: <strong>December 19, 2024</strong></p>
48-
<p><a href="https://github.com/JetBrains/kotlin/releases/tag/v2.1.20-Beta1" target="_blank">Release on GitHub</a></p>
46+
<td><strong>2.1.20-Beta2</strong>
47+
<p>Released: <strong>January 29, 2025</strong></p>
48+
<p><a href="https://github.com/JetBrains/kotlin/releases/tag/v2.1.20-Beta2" target="_blank">Release on GitHub</a></p>
4949
</td>
5050
<td>
5151
<p>A tooling release with K2 kapt enabled by default.</p>
52-
<p>For more details, please refer to the <a href="https://github.com/JetBrains/kotlin/releases/tag/v2.1.20-Beta1">changelog</a> or <a href="whatsnew-eap.md">What's new in Kotlin 2.1.20-Beta1</a>.</p>
52+
<p>For more details, please refer to the <a href="https://github.com/JetBrains/kotlin/releases/tag/v2.1.20-Beta2">changelog</a> or <a href="whatsnew-eap.md">What's new in Kotlin 2.1.20-Beta2</a>.</p>
5353
</td>
5454
</tr>
5555
</table>

docs/topics/whatsnew-eap.md

Lines changed: 172 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ The Kotlin %kotlinEapVersion% release is out!
1313
Here are some details of this EAP release:
1414

1515
* [](#kotlin-k2-compiler-new-default-kapt-plugin)
16-
* [](#gradle-support-for-version-8-11)
16+
* [](#kotlin-multiplatform-new-dsl-to-replace-gradle-s-application-plugin)
17+
* [](#common-atomic-types)
18+
* [](#changes-in-uuid-parsing-and-formatting-functions)
1719

1820
## IDE support
1921

@@ -45,6 +47,59 @@ kapt.use.k2=false
4547

4648
Please report such issues to our [issue tracker](https://youtrack.jetbrains.com/issue/KT-71439/K2-kapt-feedback).
4749

50+
## Kotlin Multiplatform: new DSL to replace Gradle's Application plugin
51+
52+
<primary-label ref="experimental-opt-in"/>
53+
54+
Starting with Gradle 8.7, the [Application](https://docs.gradle.org/current/userguide/application_plugin.html) plugin is
55+
no longer compatible with the Kotlin Multiplatform Gradle plugin. Kotlin %kotlinEapVersion% introduces an Experimental
56+
DSL to achieve similar functionality. The new `executable {}` block configures execution tasks and Gradle
57+
[distributions](https://docs.gradle.org/current/userguide/distribution_plugin.html#distribution_plugin) for JVM targets.
58+
59+
Before using the DSL, add the following to your build script:
60+
61+
```kotlin
62+
@OptIn(ExperimentalKotlinGradlePluginApi::class)
63+
```
64+
65+
Then, add the new `executable {}` block. For example:
66+
67+
```kotlin
68+
kotlin {
69+
jvm {
70+
@OptIn(ExperimentalKotlinGradlePluginApi::class)
71+
binaries {
72+
// Configures a JavaExec task named "runJvm" and a Gradle distribution for the "main" compilation in this target
73+
executable {
74+
mainClass.set("foo.MainKt")
75+
}
76+
77+
// Configures a JavaExec task named "runJvmAnother" and a Gradle distribution for the "main" compilation
78+
executable(KotlinCompilation.MAIN_COMPILATION_NAME, "another") {
79+
// Set a different class
80+
mainClass.set("foo.MainAnotherKt")
81+
}
82+
83+
// Configures a JavaExec task named "runJvmTest" and a Gradle distribution for the "test" compilation
84+
executable(KotlinCompilation.TEST_COMPILATION_NAME) {
85+
mainClass.set("foo.MainTestKt")
86+
}
87+
88+
// Configures a JavaExec task named "runJvmTestAnother" and a Gradle distribution for the "test" compilation
89+
executable(KotlinCompilation.TEST_COMPILATION_NAME, "another") {
90+
mainClass.set("foo.MainAnotherTestKt")
91+
}
92+
}
93+
}
94+
}
95+
```
96+
97+
In this example, Gradle's [Distribution](https://docs.gradle.org/current/userguide/distribution_plugin.html#distribution_plugin)
98+
plugin is applied on the first `executable {}` block.
99+
100+
If you run into any issues, report them in our [issue tracker](https://kotl.in/issue) or let us know in our
101+
[public Slack channel](https://kotlinlang.slack.com/archives/C19FD9681).
102+
48103
## Gradle: support for version 8.11
49104

50105
Kotlin %kotlinEapVersion% is now compatible with the latest stable Gradle version, 8.11, and supports its features.
@@ -54,6 +109,122 @@ We plan to fix this issue as soon as possible.
54109

55110
For more information, see the related issue in [YouTrack](https://youtrack.jetbrains.com/issue/KT-66542).
56111

112+
## Standard library
113+
114+
### Common atomic types
115+
<primary-label ref="experimental-opt-in"/>
116+
117+
In Kotlin %kotlinEapVersion%, we are introducing common atomic types in the standard library's `kotlin.concurrent.atomics`
118+
package, enabling shared, platform-independent code for thread-safe operations. This simplifies development for Kotlin
119+
Multiplatform projects by removing the need to duplicate atomic-dependent logic across source sets.
120+
121+
The `kotlin.concurrent.atomics` package and its properties are [Experimental](components-stability.md#stability-levels-explained).
122+
To opt in, use the `@OptIn(ExperimentalAtomicApi::class)` annotation or the compiler option `-opt-in=kotlin.ExperimentalAtomicApi`.
123+
124+
Here's an example that shows how you can use `AtomicInt` to safely count processed items across multiple threads:
125+
126+
```kotlin
127+
// Imports the necessary libraries
128+
import kotlin.concurrent.atomics.*
129+
import kotlinx.coroutines.*
130+
131+
//sampleStart
132+
@OptIn(ExperimentalAtomicApi::class)
133+
suspend fun main() {
134+
// Initializes the atomic counter for processed items
135+
var processedItems = AtomicInt(0)
136+
val totalItems = 100
137+
val items = List(totalItems) { "item$it" }
138+
// Splits the items into chunks for processing by multiple coroutines
139+
val chunkSize = 20
140+
val itemChunks = items.chunked(chunkSize)
141+
coroutineScope {
142+
for (chunk in itemChunks) {
143+
launch {
144+
for (item in chunk) {
145+
println("Processing $item in thread ${Thread.currentThread()}")
146+
processedItems += 1 // Increment counter atomically
147+
}
148+
}
149+
}
150+
}
151+
//sampleEnd
152+
// Prints the total number of processed items
153+
println("Total processed items: ${processedItems.load()}")
154+
}
155+
```
156+
{validate="false" kotlin-runnable="true" kotlin-min-compiler-version="2.1.20-beta2"}
157+
158+
To enable seamless interoperability between Kotlin's atomic types and Java's [`java.util.concurrent.atomic`](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/package-summary.html)
159+
atomic types, the API provides the `.asJavaAtomic()` and `.asKotlinAtomic()` extension functions. On the JVM, Kotlin
160+
atomics and Java atomics are the same types in runtime, so you can transform Java atomics to Kotlin atomics and the other
161+
way around without any overhead.
162+
163+
Let's look at an example that shows how Kotlin and Java atomic types can work together:
164+
165+
```kotlin
166+
// Imports the necessary libraries
167+
import kotlin.concurrent.atomics.*
168+
import java.util.concurrent.atomic.*
169+
170+
//sampleStart
171+
@OptIn(ExperimentalAtomicApi::class)
172+
fun main() {
173+
// Converts Kotlin AtomicInt to Java's AtomicInteger
174+
val kotlinAtomic = AtomicInt(42)
175+
val javaAtomic: AtomicInteger = kotlinAtomic.asJavaAtomic()
176+
println("Java atomic value: ${javaAtomic.get()}")
177+
// Java atomic value: 42
178+
179+
// Converts Java's AtomicInteger back to Kotlin's AtomicInt
180+
val kotlinAgain: AtomicInt = javaAtomic.asKotlinAtomic()
181+
println("Kotlin atomic value: ${kotlinAgain.load()}")
182+
// Kotlin atomic value: 42
183+
}
184+
//sampleEnd
185+
```
186+
{validate="false" kotlin-runnable="true" kotlin-min-compiler-version="2.1.20-beta2"}
187+
188+
### Changes in UUID parsing and formatting functions
189+
<primary-label ref="experimental-opt-in"/>
190+
191+
The JetBrains team continues to improve the support for UUIDs [introduced to the standard library in 2.0.20](whatsnew2020.md#support-for-uuids-in-the-common-kotlin-standard-library).
192+
193+
Previously, the `parse()` function only accepted UUIDs in the hex-and-dash format. With Kotlin %kotlinEapVersion%,
194+
you can use `parse()` for _both_ the hex-and-dash and the plain hexadecimal format (without dashes).
195+
196+
We also introduce functions specific to the operations with the hex-and-dash format in this release:
197+
198+
* `parseHexDash()` that parses UUIDs from the hex-and-dash format.
199+
* `toHexDashString()` that converts a UUID into a string in the hex-and-dash format (mirroring the `toString()` functionality).
200+
201+
These functions work similarly to [`parseHex()`](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.uuid/-uuid/-companion/parse-hex.html)
202+
and [`toHexString()`](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.uuid/-uuid/to-hex-string.html) that were
203+
introduced earlier for the hexadecimal format. Explicit naming for the parsing and formatting functionality should improve
204+
code clarity and your overall experience with UUID handling.
205+
206+
Remember that the UUID support in the standard library is still [Experimental](components-stability.md#stability-levels-explained).
207+
To opt in, use the `@ExperimentalUuidApi` annotation or the compiler option `-opt-in=kotlin.uuid.ExperimentalUuidApi`:
208+
209+
```kotlin
210+
import kotlin.uuid.ExperimentalUuidApi
211+
import kotlin.uuid.Uuid
212+
213+
//sampleStart
214+
@OptIn(ExperimentalUuidApi::class)
215+
fun main() {
216+
// Use parse() to accept a UUID in a plain hexadecimal format
217+
val uuid = Uuid.parse("550e8400e29b41d4a716446655440000")
218+
219+
// Convert it to the hex-and-dash format
220+
val hexDashFormat = uuid.toHexDashString()
221+
println(hexDashFormat)
222+
// Output: 550e8400-e29b-41d4-a716-446655440000
223+
}
224+
//sampleEnd
225+
```
226+
{validate="false" kotlin-runnable="true" kotlin-min-compiler-version="2.1.20-beta2"}
227+
57228
## How to update to Kotlin %kotlinEapVersion%
58229

59230
Starting from IntelliJ IDEA 2023.3 and Android Studio Iguana (2023.2.1) Canary 15, the Kotlin plugin is distributed as a

docs/v.list

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
<var name="apiVersion" value="2.1" type="string"/>
1414

1515
<!-- Kotlin EAP -->
16-
<var name="kotlinEapVersion" value="2.1.20-Beta1" type="string"/>
17-
<var name="kotlinEapReleaseDate" value="December 19, 2024" type="string"/>
16+
<var name="kotlinEapVersion" value="2.1.20-Beta2" type="string"/>
17+
<var name="kotlinEapReleaseDate" value="January 29, 2025" type="string"/>
1818

1919
<!-- Libraries and Frameworks -->
2020
<var name="coroutinesVersion" value="1.10.1" type="string"/>

0 commit comments

Comments
 (0)