diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJLinkTask.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJLinkTask.kt index be42b959438..754e1d4e205 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJLinkTask.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJLinkTask.kt @@ -11,6 +11,7 @@ import org.gradle.api.provider.Property import org.gradle.api.tasks.Input import org.gradle.api.tasks.InputFile import org.gradle.api.tasks.Optional +import org.gradle.process.ExecResult import org.jetbrains.compose.desktop.application.internal.RuntimeCompressionLevel import org.jetbrains.compose.desktop.application.internal.* import org.jetbrains.compose.desktop.application.internal.JavaRuntimeProperties @@ -43,6 +44,9 @@ abstract class AbstractJLinkTask : AbstractJvmToolOperationTask("jlink") { @get:Input internal val stripNativeCommands: Property = objects.notNullProperty(true) + @get:Input + internal val cds: Property = objects.notNullProperty(false) + @get:Input @get:Optional internal val compressionLevel: Property = objects.nullableProperty() @@ -56,12 +60,30 @@ abstract class AbstractJLinkTask : AbstractJvmToolOperationTask("jlink") { cliArg("--add-modules", m) } + val cds = cds.get() + cliArg("--strip-debug", stripDebug) cliArg("--no-header-files", noHeaderFiles) cliArg("--no-man-pages", noManPages) - cliArg("--strip-native-commands", stripNativeCommands) + // Native commands cannot be stripped if CDS is enabled, because bin/java is used by the CDS option. + if (!cds) { + cliArg("--strip-native-commands", stripNativeCommands) + } + cliArg("--generate-cds-archive", cds) cliArg("--compress", compressionLevel.orNull?.id) cliArg("--output", destinationDir) } + + override fun checkResult(result: ExecResult) { + super.checkResult(result) + if (stripNativeCommands.get() && cds.get()) { + // Native files were not removed yet, so do it here. + destinationDir.get().asFile.walk().forEach { file -> + if (file.isDirectory && file.name == "bin") { + file.deleteRecursively() + } + } + } + } } \ No newline at end of file