Last active
December 14, 2022 00:29
-
-
Save mkobit/e06ddf93fcb9a67ded3426bd5a266bed to your computer and use it in GitHub Desktop.
Run Kotlin REPL with built source code and main classpath in Gradle
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
// Assuming Kotlin plugin is applied... | |
// Run as: ./gradlew kotlinRepl --console plain --no-daemon | |
val kotlinRepl by tasks.creating { | |
description = "Starts Kotlin REPL with compiled main classes and runtime classpath" | |
val mainSourceSet = java.sourceSets["main"] | |
dependsOn(mainSourceSet.output) | |
doFirst { | |
val buildscriptClasspath = rootProject.buildscript.configurations["classpath"] | |
val kotlinPluginJars = buildscriptClasspath | |
.resolvedConfiguration | |
.resolvedArtifacts | |
.filter { it.moduleVersion.id.group == "org.jetbrains.kotlin" } | |
.map { it.file } | |
val mainClasspath = mainSourceSet.runtimeClasspath.joinToString(separator = ":") | |
javaexec { | |
classpath = files(kotlinPluginJars) | |
main = "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler" | |
standardInput = System.`in` | |
args("-cp", mainClasspath) | |
} | |
} | |
} |
thank you! <3
This is so great! Thank you
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://youtrack.jetbrains.com/issue/KT-10310 is for native support in the Kotlin plugin