-
-
Save Tapchicoma/560054bee1eb8d953dad842efa12188e to your computer and use it in GitHub Desktop.
Run Kotlin REPL with built source code and main classpath in Gradle
This file contains hidden or 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 { | |
dependsOn("assemble") | |
doFirst { | |
val buildscriptClasspath = rootProject.buildscript.configurations["classpath"] | |
val embeddedableCompiler = buildscriptClasspath | |
.resolvedConfiguration | |
.resolvedArtifacts | |
.first { it.name == "kotlin-compiler-embeddable" } | |
val jarLocation = embeddedableCompiler.file | |
val mainClasspath = java.sourceSets["main"].runtimeClasspath.joinToString(separator = ":") | |
javaexec { | |
classpath = files(jarLocation) | |
main = "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler" | |
standardInput = System.`in` | |
args("-cp", mainClasspath) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment