diff --git a/build.gradle.kts b/build.gradle.kts index 3f95b39c9c..f4b9ef1476 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,5 @@ import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import org.jetbrains.dokka.gradle.DokkaTask import org.jetbrains.kotlin.gradle.dsl.JsSourceMapEmbedMode import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation @@ -34,7 +35,7 @@ plugins { kotlin("plugin.serialization") version Versions.kotlin id("org.jetbrains.dokka") version Versions.dokka id("com.google.devtools.ksp") version Versions.ksp - id("com.github.johnrengelman.shadow") version "8.1.1" + id("com.gradleup.shadow") version "8.3.0" id("com.github.ben-manes.versions") version "0.39.0" id("maven-publish") id("name.remal.check-dependency-updates") version "1.0.211" @@ -52,12 +53,14 @@ repositories { group = "org.baaahs" version = "0.0.1" +val JVM_VERSION = 19 + fun kotlinw(target: String): String = "org.jetbrains.kotlin-wrappers:kotlin-$target" kotlin { jvmToolchain { - languageVersion = JavaLanguageVersion.of(19) + languageVersion = JavaLanguageVersion.of(JVM_VERSION) vendor = JvmVendorSpec.ADOPTIUM } @@ -124,11 +127,6 @@ kotlin { } implementation("com.danielgergely.kgl:kgl-lwjgl:${Versions.kgl}") - // GLSL support via JOGL: - implementation("org.jogamp.gluegen:gluegen-rt-main:${Versions.jogl}") - implementation("org.jogamp.jogl:jogl-all-main:${Versions.jogl}") -// implementation("com.danielgergely.kgl:kgl-jogl:${Versions.kgl}") - // MDNS support: implementation("org.jmdns:jmdns:3.5.7") @@ -236,22 +234,29 @@ application { if (isMac()) { applicationDefaultJvmArgs += listOf( "-XstartOnFirstThread", // required for OpenGL: https://github.com/LWJGL/lwjgl3/issues/311 - "-Djava.awt.headless=true" // required for Beat Link; otherwise we get this: https://jogamp.org/bugzilla/show_bug.cgi?id=485 ) } } -// include JS artifacts in any JAR we generate -tasks.named("jvmJar").configure { +fun findWebpackTask(): TaskProvider { val taskName = if (isProductionBuild || project.gradle.startParameter.taskNames.contains("installDist")) { "jsBrowserProductionWebpack" } else { "jsBrowserDevelopmentWebpack" } + return tasks.named(taskName) +} + +tasks.named("jvmJar").configure { + // include JS artifacts in jar + from(findWebpackTask().map { it.outputDirectory.file(it.mainOutputFileName) }) { + into("htdocs") + } +} - // bring output file along into the JAR - val webpackTask = tasks.named(taskName) - from(webpackTask.map { it.outputDirectory.file(it.mainOutputFileName) }) { +tasks.named("shadowJar") { + // include JS artifacts in shadow jar + from(findWebpackTask().map { it.outputDirectory.file(it.mainOutputFileName) }) { into("htdocs") } } @@ -351,6 +356,91 @@ tasks.withType { } } +tasks.register("macApp") { + group = "application" + description = "Creates a macOS .app bundle for Sparkle Motion." + + val shadowJarTask = tasks.named("shadowJar") + dependsOn(shadowJarTask) + + val appName = "Sparkle Motion" + val appDir = buildDir("$appName.app") + val contentsDir = "$appDir/Contents" + val macosDir = "$contentsDir/MacOS" + val resourcesDir = "$contentsDir/Resources" + val javaDir = "$contentsDir/Java" + + doLast { + copy { + from(shadowJarTask) { + include("*.jar") + rename { "sparklemotion.jar" } + } + into(javaDir) + } + + copy { + from("src/macApp/resources/SparkleMotion.icns") + into(resourcesDir) + } + + // Create MacOS directory and add executable script + mkdir(macosDir) + val javaArgs = listOf( + "-Xms512m", "-Xmx2048m", + "-Dapple.laf.useScreenMenuBar=true", + "-Xdock:name='Sparkle Motion'", + "-Xdock:icon=\"\$DIR/Contents/Resources/SparkleMotion.icns\"", + "-XstartOnFirstThread", + "-jar \"\$DIR/Contents/Java/sparklemotion.jar\"" + ) + file("$macosDir/SparkleMotion").writeText(""" + #!/bin/bash + DIR="$(cd "$(dirname "$0")" && pwd)/../.." + java ${javaArgs.joinToString(" ")} + """.trimIndent()) + file("$macosDir/SparkleMotion").setExecutable(true) + + // Create Info.plist + file("$contentsDir/Info.plist").writeText(""" + + + + + CFBundleName + $appName + CFBundleDisplayName + $appName + CFBundleIdentifier + com.example.sparklemotion + CFBundleVersion + 1.0 + CFBundleShortVersionString + 1.0 + CFBundleExecutable + SparkleMotion + CFBundlePackageType + APPL + CFBundleSignature + ???? + CFBundleIconFile + SparkleMotion.icns + LSMinimumSystemVersion + 10.9.0 + NSPrincipalClass + NSApplication + LSApplicationCategoryType + public.app-category.developer-tools + + + """.trimIndent()) + } +} + +tasks.build { + dependsOn(tasks.named("macApp")) +} + // Janky. See https://github.com/google/ksp/issues/963#issuecomment-1780330007. gradle.projectsEvaluated { tasks { diff --git a/src/macApp/resources/SparkleMotion.icns b/src/macApp/resources/SparkleMotion.icns new file mode 100644 index 0000000000..be2b9ef144 Binary files /dev/null and b/src/macApp/resources/SparkleMotion.icns differ