summaryrefslogtreecommitdiff
path: root/desktop/build.gradle.kts
blob: 2a9287bc5c6e079187543ad683724276b2344a54 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import org.jetbrains.compose.desktop.application.dsl.TargetFormat

plugins {
    alias(libs.plugins.kotlin.jvm)
    alias(libs.plugins.kotlin.compose)
    alias(libs.plugins.compose)
}

kotlin { jvmToolchain(21) }

dependencies {
    implementation(project(":ui"))
    implementation(compose.desktop.currentOs)
    implementation(libs.coroutines.swing)
}

compose.desktop {
    application {
        mainClass = "coffee.liz.rookery.desktop.MainKt"
        jvmArgs += listOf("-Xmx256m", "-XX:+UseSerialGC")
        nativeDistributions {
            // From `./gradlew :desktop:suggestRuntimeModules`; jdk.security.auth is needed by dbus-java (Bluetooth).
            modules("java.instrument", "java.net.http", "jdk.security.auth", "jdk.unsupported")
            targetFormats(TargetFormat.AppImage, TargetFormat.Deb, TargetFormat.Dmg)
            macOS {
                // The alert penguin (same icns the site/macos-app.sh bundle uses).
                iconFile = rootProject.file("site/assets/rookery.icns")
                infoPlist {
                    extraKeysRawXml = """
                        <key>NSBluetoothAlwaysUsageDescription</key><string>Connects to your smart cube.</string>
                        <key>NSMicrophoneUsageDescription</key><string>Listens to a stackmat timer on an audio input.</string>
                    """
                }
            }
            packageName = "rookery"
            packageVersion = "0.1.0"
        }
    }
}

// `./gradlew :desktop:run --args="--import file.txt"` passes args through; env lets tests point at a scratch home.
tasks.withType<JavaExec>().configureEach {
    environment.putAll(System.getenv().filterKeys { it.startsWith("XDG_") || it.startsWith("ROOKERY_") })
    standardInput = System.`in` // so `--cube monitor` can take commands
}

// One jar that runs anywhere: the app plus the native graphics libraries for every desktop platform.
// (Compose's own uber jar only carries the natives of the machine that built it.)
val universal: Configuration by configurations.creating { extendsFrom(configurations.runtimeClasspath.get()) }
dependencies {
    universal(compose.desktop.linux_x64)
    universal(compose.desktop.linux_arm64)
    universal(compose.desktop.macos_x64)
    universal(compose.desktop.macos_arm64)
    universal(compose.desktop.windows_x64)
}

interface ArchiveServices { @get:javax.inject.Inject val archives: ArchiveOperations }
val archives = objects.newInstance<ArchiveServices>().archives // an injected service, so the configuration cache can store it

tasks.register<Jar>("universalJar") {
    group = "distribution"
    archiveBaseName = "rookery"
    archiveClassifier = "universal"
    manifest { attributes["Main-Class"] = "coffee.liz.rookery.desktop.MainKt" }
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    from(sourceSets.main.get().output)
    val unzip = archives // a local, so the closure below captures the service and not the whole build script
    from(universal.elements.map { files -> files.filter { it.asFile.name.endsWith(".jar") }.map { unzip.zipTree(it.asFile) } })
    exclude("META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA", "META-INF/INDEX.LIST")
}