Skip to content

Instantly share code, notes, and snippets.

@dant3
Forked from mkobit/build.gradle.kts
Created April 29, 2018 05:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dant3/8f9e741ca8e456369b7b48c2bf209138 to your computer and use it in GitHub Desktop.
Save dant3/8f9e741ca8e456369b7b48c2bf209138 to your computer and use it in GitHub Desktop.
Run Kotlin REPL with built source code and main classpath in Gradle
// 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)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment