From ddc300f0fee7b066318092a20b96d1f7a7331b69 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Tue, 4 Apr 2023 13:59:55 +0200 Subject: [PATCH] Fix passing relative path main jar to jpackage --- .../desktop/application/internal/files/fileUtils.kt | 9 +++++++-- .../desktop/application/tasks/AbstractJPackageTask.kt | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/files/fileUtils.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/files/fileUtils.kt index 04bf09def5..64a314ad22 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/files/fileUtils.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/files/fileUtils.kt @@ -108,5 +108,10 @@ internal fun File.checkExistingFile(): File = internal val File.isJarFile: Boolean get() = name.endsWith(".jar", ignoreCase = true) && isFile -internal fun File.normalizedPath() = - if (currentOS == OS.Windows) absolutePath.replace("\\", "\\\\") else absolutePath +internal fun File.normalizedPath(base: File? = null): String { + val path = base?.let { relativeToOrNull(it)?.path } ?: absolutePath + return when (currentOS) { + OS.Windows -> path.replace("\\", "\\\\") + else -> path + } +} \ No newline at end of file diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt index ae3b88c40f..30836d61eb 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt @@ -321,8 +321,8 @@ abstract class AbstractJPackageTask @Inject constructor( val mappedJar = libsMapping[launcherMainJar.ioFile]?.singleOrNull() ?: error("Main jar was not processed correctly: ${launcherMainJar.ioFile}") - val mainJarRelative = (if (currentTarget.os == OS.Windows) "\\" else "/") + mappedJar.relativeTo(libsDir.ioFile).toString() - cliArg("--main-jar", mainJarRelative) + val mainJarPath = mappedJar.normalizedPath(base = libsDir.ioFile) + cliArg("--main-jar", mainJarPath) cliArg("--main-class", launcherMainClass) if (currentOS == OS.Windows) {