S1ckret-Labs / git-jump

A CLI navigation helper for Git

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Git Jump

How to build

./gradlew clean build

How to launch

# From the project root folder
cd build/distributions/
tar -xvf ./gitj-0.0.1.tar
./git-jump-0.0.1/bin/git-jump

Kotlin Multiplatform encountered problems

Build related

  1. It doesn't build uberJar (fatJar) by default
  2. It doesn't build zip/tar with dependencies by default
  3. Resulted jar doesn't have Main-Class, Class-Path attributes
  4. Since the project doesn't have java plugin we can't apply "default" solutions
  5. Cannot change dependencies of dependency configuration ':jvmApi' after it has been included in dependency resolution.

Solution

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.

  1. 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
  1. 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
  1. Add Main-Class and Class-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

Links

Contributed

Answered to How to execute Kotlin Multiplatform Jar

About

A CLI navigation helper for Git


Languages

Language:Kotlin 100.0%