Drive kotlinc from build.gradle
// Execute Kotlin script with: | |
// | |
// gradle -q foo | |
// | |
// For correctness, we're going to configure two independent classpath configurations, one for kotlinc and the other for the | |
// script(s) we want to execute. | |
configurations { | |
kotlinc | |
scripts | |
} | |
ext.kotlinVersion = "1.1.0-rc-91" | |
repositories { | |
maven { url 'http://dl.bintray.com/kotlin/kotlin-eap-1.1' } | |
jcenter() | |
} | |
def kotlinModule(String name) { | |
"org.jetbrains.kotlin:kotlin-$name:$kotlinVersion" | |
} | |
dependencies { | |
kotlinc(kotlinModule("compiler")) | |
kotlinc(kotlinModule("stdlib")) | |
kotlinc(kotlinModule("runtime")) | |
kotlinc(kotlinModule("reflect")) | |
kotlinc(kotlinModule("script-runtime")) | |
// Our simple script depends only on the stdlib but additional dependencies could be | |
// added to this configuration. | |
scripts(kotlinModule("stdlib")) | |
} | |
def kotlinHome = file("$buildDir/kotlin") | |
task prepareKotlinHome(type: Copy) { | |
from(configurations.kotlinc) | |
into("$kotlinHome/lib") | |
rename { | |
// strip the version suffix to satisfy the compiler | |
(it - "-${kotlinVersion}.jar") + ".jar" | |
} | |
} | |
task foo(type: JavaExec) { | |
group "My" | |
description "Executes foo.kts" | |
dependsOn prepareKotlinHome | |
main = "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler" | |
classpath = configurations.kotlinc | |
args( | |
"-kotlin-home", kotlinHome, | |
"-classpath", configurations.scripts.asPath, | |
"-script", "foo.kts") | |
} | |
This comment has been minimized.
This comment has been minimized.
Here are the updated dependencies for Kotlin 1.3.72:
|
This comment has been minimized.
This comment has been minimized.
How would this build script looked in Kotlin DSL? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
It does not work for me: I get "error: unable to evaluate script, no scripting plugin loaded"