./gradlew clean build
# From the project root folder
cd build/distributions/
tar -xvf ./gitj-0.0.1.tar
./git-jump-0.0.1/bin/git-jump
- It doesn't build uberJar (fatJar) by default
- It doesn't build zip/tar with dependencies by default
- Resulted jar doesn't have
Main-Class
,Class-Path
attributes - Since the project doesn't have
java
plugin we can't apply "default" solutions - Cannot change dependencies of dependency configuration ':jvmApi' after it has been included in dependency resolution.
I decided to build distribution rather than uberJar because in that way I don't override manifests in dependent libraries. But I am sure we can easily create uberJar from those pieces.
UPD: I switched to application
plugin since it does what I want.
- Create a distribution
The first into block copies your jar that is build by Kotlin Multiplatform jvmJar
task.
The second into block copies your runtime dependency files. (Analogue to configurations.runtimeClasspath.get() from java
plugin)
distributions {
main {
distributionBaseName.set("gitj")
contents {
into("") {
val jvmJar by tasks.getting
from(jvmJar)
}
into("libs/") {
val main by kotlin.jvm().compilations.getting
from(main.runtimeDependencyFiles)
}
}
}
}
On this step we can launch our application with this command
java -cp 'git-jump-jvm-0.0.1.jar:libs/*' com.s1ckret.labs.gitj.MainKt
- Add
Main-Class
attribute to manifest
tasks.withType<Jar> {
manifest {
attributes(
"Main-Class" to "com.s1ckret.labs.gitj.MainKt",
)
}
}
On this step we can launch our application with this command
java -cp 'git-jump-jvm-0.0.1.jar:libs/*' com.s1ckret.labs.gitj.MainKt
- Add
Main-Class
andClass-Path
attributes to manifest
It is very important to wrap with doFirst
function, otherwise problem #5 is showing up
tasks.withType<Jar> {
doFirst {
manifest {
val main by kotlin.jvm().compilations.getting
attributes(
"Main-Class" to "com.s1ckret.labs.gitj.MainKt",
"Class-Path" to main.runtimeDependencyFiles.files.joinToString(" ") { "libs/" + it.name }
)
}
}
}
On this step we can launch our application with this command
java -jar git-jump-jvm-0.0.1.jar
- https://stackoverflow.com/questions/22659463/add-classpath-in-manifest-using-gradle
- https://stackoverflow.com/questions/42552511/cannot-change-dependencies-of-configuration-compile-after-it-has-been-resolve
- https://stackoverflow.com/questions/15930782/call-java-jar-myfile-jar-with-additional-classpath-option
- https://stackoverflow.com/questions/44197521/gradle-project-java-lang-noclassdeffounderror-kotlin-jvm-internal-intrinsics
- https://stackoverflow.com/questions/56921833/kotlin-program-error-no-main-manifest-attribute-in-jar-file
- https://stackoverflow.com/questions/68561300/kotlin-multiplatform-library-unresolved-dependency-at-runtime
- https://stackoverflow.com/questions/25398703/gradle-analogue-for-maven-assembly-plugin
- https://docs.gradle.org/current/userguide/working_with_files.html#sec:creating_uber_jar_example
- https://docs.gradle.org/current/userguide/distribution_plugin.html
Answered to How to execute Kotlin Multiplatform Jar