Skip to content

Commit

Permalink
Use GraalVM to build single binary
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Feb 12, 2025
1 parent 7b65746 commit 79ef299
Show file tree
Hide file tree
Showing 4 changed files with 1,023 additions and 44 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/client.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ jobs:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
- uses: graalvm/setup-graalvm@v1
with:
distribution: "temurin"
java-version: "23"
java-version: '23'
distribution: 'graalvm-community'
components: 'native-image'
- uses: gradle/actions/setup-gradle@v4
- run: ./gradlew client:packageDist
- run: ./gradlew client:nativeCompile
- name: Release
uses: softprops/action-gh-release@v2
if: ${{ github.ref == 'refs/heads/main' }}
with:
tag_name: ${{ github.run_number }}
files: client/build/dist/*.tar.gz
files: client/build/native/nativeCompile/client.exe
51 changes: 18 additions & 33 deletions client/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import org.panteleyev.jpackage.ImageType

plugins {
id("buildsrc.convention.kotlin-jvm")
id("org.panteleyev.jpackageplugin") version "1.6.1"
id("org.graalvm.buildtools.native") version "0.10.5"
application
}

version = "1.0.0"

configurations {
nativeImageCompileOnly {
isCanBeResolved = true
}
}

dependencies {
implementation(libs.jnativehook)
implementation(libs.ktor.client.okhttp)
Expand All @@ -15,37 +20,17 @@ dependencies {
implementation(libs.slf4j.simple)
}

tasks {
val copyDependencies by registering(Copy::class) {
from(configurations.runtimeClasspath).into(layout.buildDirectory.dir("jars"))
}

val copyJar by registering(Copy::class) {
from(jar).into(layout.buildDirectory.dir("jars"))
}

jpackage {
dependsOn(build, copyDependencies, copyJar)
winConsole = true

input = layout.buildDirectory.dir("jars").get().asFile.absolutePath

appName = "GTA KILL"
vendor = "Schlaubi"
type = ImageType.APP_IMAGE

mainJar = jar.get().archiveFile.get().asFile.absolutePath
mainClass = "dev.schlaubi.mastermind.MainKt"

destination = layout.buildDirectory.dir("dist").get().asFile.absolutePath
}
application {
mainClass = "dev.schlaubi.mastermind.MainKt"
applicationDefaultJvmArgs = listOf("-agentlib:native-image-agent=config-output-dir=C:\\Users\\micha\\IdeaProjects\\gtakiller\\output.json")
}

register<Tar>("packageDist") {
dependsOn(jpackage)
from(jpackage.get().destination + "/" + jpackage.get().appName)
graalvmNative {
toolchainDetection = true

compression = Compression.GZIP
archiveExtension = "tar.gz"
destinationDirectory = layout.buildDirectory.dir("dist")
binaries {
named("main") {
mainClass = "dev.schlaubi.mastermind.MainKt"
}
}
}
Loading

0 comments on commit 79ef299

Please sign in to comment.