1+ import org.gradle.kotlin.dsl.support.zipTo
12import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
23import org.jetbrains.compose.desktop.application.dsl.TargetFormat
34import org.jetbrains.compose.desktop.application.tasks.AbstractJPackageTask
@@ -105,6 +106,8 @@ tasks.compileJava{
105106 options.encoding = " UTF-8"
106107}
107108
109+ val version = if (project.version == " unspecified" ) " 1.0.0" else project.version
110+
108111tasks.register<Exec >(" installCreateDmg" ) {
109112 onlyIf { org.gradle.internal.os.OperatingSystem .current().isMacOsX }
110113 commandLine(" arch" , " -arm64" , " brew" , " install" , " --quiet" , " create-dmg" )
@@ -185,11 +188,6 @@ tasks.register("generateSnapConfiguration"){
185188 val distributable = tasks.named<AbstractJPackageTask >(" createDistributable" ).get()
186189 dependsOn(distributable)
187190
188-
189-
190- val version = if (version == " unspecified" ) " 1.0.0" else version
191-
192-
193191 val dir = distributable.destinationDir.get()
194192 val content = """
195193 name: $snapname
@@ -399,16 +397,48 @@ tasks.register<Copy>("renameWindres") {
399397}
400398tasks.register<Exec >(" signResources" ){
401399 onlyIf { org.gradle.internal.os.OperatingSystem .current().isMacOsX }
402- val distributable = tasks.named<AbstractJPackageTask >(" createDistributable" ).get()
403- dependsOn(distributable)
400+ group = " compose desktop"
401+ dependsOn(" prepareAppResources" )
402+
403+ val resourcesPath = composeResources(" " )
404+
405+
406+
407+ // find jars in the resources directory
408+ val jars = mutableListOf<File >()
409+ doFirst{
410+ fileTree(resourcesPath)
411+ .matching { include(" **/Info.plist" ) }
412+ .singleOrNull()
413+ ?.let { file ->
414+ copy {
415+ from(file)
416+ into(resourcesPath)
417+ }
418+ }
419+ fileTree(resourcesPath) {
420+ include(" **/*.jar" )
421+ exclude(" **/*.jar.tmp/**" )
422+ }.forEach { file ->
423+ val tempDir = file.parentFile.resolve(" ${file.name} .tmp" )
424+ copy {
425+ from(zipTree(file))
426+ into(tempDir)
427+ }
428+ jars.add(tempDir)
429+ }
430+ }
431+ commandLine(" codesign" ," --timestamp" , " --force" ," --deep" , " --sign" , " Developer ID Application" , resourcesPath.get().asFile)
432+ doLast {
433+ jars.forEach { file ->
434+ zipTo(file.resolve(file.nameWithoutExtension), file)
435+
436+ file.deleteRecursively()
437+ }
438+ file(composeResources(" Info.plist" )).delete()
439+ }
440+
404441
405- commandLine(
406- " codesign" ,
407- " --force" ,
408- " --deep" ,
409- " --sign" , " Developer ID Application" ,
410- distributable.destinationDir.get().file(distributable.packageName.get() + " .app" ).asFile
411- )
412442}
413443afterEvaluate {
414444 tasks.named(" prepareAppResources" ).configure {
@@ -443,5 +473,8 @@ afterEvaluate {
443473 }
444474 }
445475 }
446- tasks.findByName(" createDistributable" )?.finalizedBy(" setExecutablePermissions" , " signResources" )
476+ tasks.named(" createDistributable" ).configure {
477+ dependsOn(" signResources" )
478+ finalizedBy(" setExecutablePermissions" )
479+ }
447480}
0 commit comments