forked from pfn/kotlin-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3637504
commit d711eab
Showing
5 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import kotlin.Keys._ | ||
|
||
enablePlugins(KotlinPlugin) | ||
kotlinLib("stdlib") | ||
|
||
kotlinVersion := "1.9.20" | ||
kotlincJvmTarget := "1.8" | ||
|
||
val listClasses = taskKey[Unit]("listClasses") | ||
|
||
listClasses := { | ||
val classes = (Compile / classDirectory).value.listFiles() | ||
streams.value.log.info("classes: " + classes.mkString("Array(", ", ", ")")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
sys.props.get("plugin.version") match { | ||
case Some(version) => addSbtPlugin("org.jetbrains.scala" % "sbt-kotlin-plugin" % version) | ||
case _ => sys.error( | ||
"""The system property 'plugin.version' is not defined. | ||
|Specify this property using the scriptedLaunchOpts -Dplugin.version.""".stripMargin) | ||
} |
3 changes: 3 additions & 0 deletions
3
src/sbt-test/kotlin/kotlin-1.9-compat/src/main/kotlin/SimpleScript.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// This script is not supposed to be inside source root. Since Kotlin 1.9 it is ignored during the module compilation. | ||
// See https://youtrack.jetbrains.com/issue/KT-52735 | ||
println("Hello world!") |
34 changes: 34 additions & 0 deletions
34
src/sbt-test/kotlin/kotlin-1.9-compat/src/main/kotlin/demo/simple.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package demo | ||
|
||
fun main(args: Array<String>) { | ||
// Test some Kotlin 1.9 features | ||
println(findByRgb("#FF0000")) | ||
println(Person("John", "Doe")) | ||
} | ||
|
||
enum class Color(val colorName: String, val rgb: String) { | ||
RED("Red", "#FF0000"), | ||
ORANGE("Orange", "#FF7F00"), | ||
YELLOW("Yellow", "#FFFF00") | ||
} | ||
|
||
// In 1.8.20, the entries property for enum classes was introduced as an Experimental feature. | ||
// The entries property is a modern and performant replacement for the synthetic values() function. | ||
// In 1.9.0, the entries property is Stable. | ||
fun findByRgb(rgb: String): Color? = Color.entries.find { it.rgb == rgb } | ||
|
||
@JvmInline | ||
value class Person(private val fullName: String) { | ||
// Allowed since Kotlin 1.4.30: | ||
init { | ||
check(fullName.isNotBlank()) { | ||
"Full name shouldn't be empty" | ||
} | ||
} | ||
// Allowed by default since Kotlin 1.9.0: | ||
constructor(name: String, lastName: String) : this("$name $lastName") { | ||
check(lastName.isNotBlank()) { | ||
"Last name shouldn't be empty" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
> compile | ||
> listClasses | ||
$ exists target/scala-2.12/classes/demo/SimpleKt.class | ||
$ absent target/scala-2.12/classes/SimpleScript.class |