I'm using Gradle with Kotlin-DSL, but I couldn't find a way to generate an executable jar, so I'll write it down as a memorandum.
build.gradle.kts
plugins {
application
}
dependencies {
//To jar the dependent libraries'compile'Must be described in
// Use the Kotlin JDK 8 standard library.
compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
// Use the Kotlin test library.
testCompile("org.jetbrains.kotlin:kotlin-test")
// Use the Kotlin JUnit integration.
testCompile("org.jetbrains.kotlin:kotlin-test-junit")
}
application {
// Define the main class for the application
mainClassName = "com.example.MainKt"
}
// 'gradle jar'Define a task so that you can use
val jar by tasks.getting(Jar::class) {
manifest {
attributes["Main-Class"] = "com.example.MainKt"
}
from(
configurations.compile.get().map {
if (it.isDirectory) it else zipTree(it)
}
)
exclude("META-INF/*.RSA", "META-INF/*.SF", "META-INF/*.DSA")
}
I can find a lot of groovy articles ...
[11/4 postscript]
Although it deviates from the purpose of this article, I will also write a method to give run-time arguments at the time of ./gradlew run
execution.
build.gradle.kts
import kotlin.text.Regex
val run by tasks.getting(JavaExec::class) {
if (project.hasProperty("args")) {
args = (project.property("args") as String).split(Regex("\\s+))
}
}
At runtime
./gradlew run -Pargs="hoge fuga piyo ..."
Note that the arguments do not complete
Recommended Posts