Skip to content

Commit

Permalink
Create executable jar
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Brooks committed Sep 28, 2020
1 parent df91a9d commit f72855d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ jobs:
with:
name: integration_test_results
path: vgo/build/reports/tests/integrationTest
- name: optimize
run: ./gradlew optimize
- name: release binary
run: ./gradlew binary
- name: archive vgo
uses: actions/upload-artifact@v1
with:
name: vgo.jar
path: vgo/build/libs/vgo.jar
name: vgo
path: vgo/build/libs/vgo
21 changes: 20 additions & 1 deletion vgo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.io.FileInputStream
import java.io.PrintWriter
import java.nio.file.Files
import java.nio.file.Paths
import java.util.*
import java.util.Properties

plugins {
id("org.jetbrains.kotlin.jvm")
Expand Down Expand Up @@ -93,10 +93,14 @@ tasks {
from(configurations.runtimeClasspath.get().filter { it.isFile }.map(::zipTree))
}

val optimizedJar = file("$buildDir/libs/vgo.jar")
val optimize by registering(JavaExec::class) {
description = "Runs proguard on the jar application."
group = "build"

inputs.file("$buildDir/libs/debug/vgo.jar")
outputs.file(optimizedJar)

val javaHome = System.getenv("JAVA_HOME") ?: javaInstalls
.installationForCurrentVirtualMachine.get()
.installationDirectory.toString()
Expand All @@ -114,6 +118,21 @@ tasks {
dependsOn(getByName("jar"))
}

val binaryFile = file("$buildDir/libs/vgo")
val binary by registering {
dependsOn(optimize)
inputs.file(optimizedJar)
outputs.file(binaryFile)

doLast {
binaryFile.parentFile.mkdirs()
binaryFile.delete()
binaryFile.appendText("#!/bin/sh\n\nexec java \$JAVA_OPTS -jar \$0 \"\$@\"\n\n")
optimizedJar.inputStream().use { binaryFile.appendBytes(it.readBytes()) }
binaryFile.setExecutable(true, false)
}
}

val integrationTest by registering(Test::class) {
description = "Runs the integration tests."
group = "verification"
Expand Down

0 comments on commit f72855d

Please sign in to comment.