Browse Source

Fix packaging with JDK 19 (#2439)

Resolves #2328
pull/2442/head
Alexey Tsvetkov 2 years ago committed by GitHub
parent
commit
6501d9f9f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt
  2. 20
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/DesktopApplicationTest.kt
  3. 34
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProject.kt
  4. 1
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProjects.kt
  5. 34
      gradle-plugins/compose/src/test/test-projects/application/customJavaHome/build.gradle
  6. 11
      gradle-plugins/compose/src/test/test-projects/application/customJavaHome/settings.gradle
  7. 18
      gradle-plugins/compose/src/test/test-projects/application/customJavaHome/src/main/kotlin/main.kt

7
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt

@ -231,6 +231,8 @@ abstract class AbstractJPackageTask @Inject constructor(
@get:Optional @get:Optional
val javaRuntimePropertiesFile: RegularFileProperty = objects.fileProperty() val javaRuntimePropertiesFile: RegularFileProperty = objects.fileProperty()
private lateinit var jvmRuntimeInfo: JvmRuntimeProperties
@get:Optional @get:Optional
@get:Nested @get:Nested
internal var nonValidatedMacSigningSettings: MacOSSigningSettings? = null internal var nonValidatedMacSigningSettings: MacOSSigningSettings? = null
@ -339,7 +341,7 @@ abstract class AbstractJPackageTask @Inject constructor(
if (targetFormat != TargetFormat.AppImage) { if (targetFormat != TargetFormat.AppImage) {
// Args, that can only be used, when creating an installer // Args, that can only be used, when creating an installer
if (currentOS == OS.MacOS && macAppStore.orNull == true) { if (currentOS == OS.MacOS && jvmRuntimeInfo.majorVersion >= 18) {
// This is needed to prevent a directory does not exist error. // This is needed to prevent a directory does not exist error.
cliArg("--app-image", appImage.dir("${packageName.get()}.app")) cliArg("--app-image", appImage.dir("${packageName.get()}.app"))
} else { } else {
@ -444,7 +446,6 @@ abstract class AbstractJPackageTask @Inject constructor(
fileOperations.delete(tmpDirForSign) fileOperations.delete(tmpDirForSign)
tmpDirForSign.mkdirs() tmpDirForSign.mkdirs()
val jvmRuntimeInfo = JvmRuntimeProperties.readFromFile(javaRuntimePropertiesFile.ioFile)
MacJarSignFileCopyingProcessor( MacJarSignFileCopyingProcessor(
signer, signer,
tmpDirForSign, tmpDirForSign,
@ -543,6 +544,8 @@ abstract class AbstractJPackageTask @Inject constructor(
} }
override fun initState() { override fun initState() {
jvmRuntimeInfo = JvmRuntimeProperties.readFromFile(javaRuntimePropertiesFile.ioFile)
val mappingFile = libsMappingFile.ioFile val mappingFile = libsMappingFile.ioFile
if (mappingFile.exists()) { if (mappingFile.exists()) {
try { try {

20
gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/DesktopApplicationTest.kt

@ -127,6 +127,26 @@ class DesktopApplicationTest : GradlePluginTestBase() {
testPackageJvmDistributions() testPackageJvmDistributions()
} }
private fun customJavaHomeProject(javaVersion: Int): TestProject =
testProject(
TestProjects.customJavaHome,
defaultTestEnvironment.copy(customJavaToolchainVersion = javaVersion)
)
@Test
fun testJdk15() = with(customJavaHomeProject(15)) {
testPackageJvmDistributions()
}
@Test
fun testJdk18() = with(customJavaHomeProject(18)) {
testPackageJvmDistributions()
}
@Test
fun testJdk19() = with(customJavaHomeProject(19)) {
testPackageJvmDistributions()
}
private fun TestProject.testPackageJvmDistributions() { private fun TestProject.testPackageJvmDistributions() {
val result = gradle(":packageDistributionForCurrentOS").build() val result = gradle(":packageDistributionForCurrentOS").build()
val ext = when (currentOS) { val ext = when (currentOS) {

34
gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProject.kt

@ -13,8 +13,26 @@ data class TestEnvironment(
val workingDir: File, val workingDir: File,
val kotlinVersion: String = TestKotlinVersions.Default, val kotlinVersion: String = TestKotlinVersions.Default,
val composeGradlePluginVersion: String = TestProperties.composeGradlePluginVersion, val composeGradlePluginVersion: String = TestProperties.composeGradlePluginVersion,
val composeCompilerArtifact: String? = null val composeCompilerArtifact: String? = null,
) val customJavaToolchainVersion: Int? = null
) {
private val placeholders = linkedMapOf(
"COMPOSE_GRADLE_PLUGIN_VERSION_PLACEHOLDER" to composeGradlePluginVersion,
"KOTLIN_VERSION_PLACEHOLDER" to kotlinVersion,
"COMPOSE_COMPILER_ARTIFACT_PLACEHOLDER" to composeCompilerArtifact,
"CUSTOM_JAVA_TOOLCHAIN_VERSION_PLACEHOLDER" to customJavaToolchainVersion?.toString()
)
fun replacePlaceholdersInFile(file: File) {
var content = file.readText()
for ((placeholder, value) in placeholders.entries) {
if (value != null) {
content = content.replace(placeholder, value)
}
}
file.writeText(content)
}
}
class TestProject( class TestProject(
private val name: String, private val name: String,
@ -36,18 +54,10 @@ class TestProject(
val target = testEnvironment.workingDir.resolve(orig.relativeTo(originalTestRoot)) val target = testEnvironment.workingDir.resolve(orig.relativeTo(originalTestRoot))
target.parentFile.mkdirs() target.parentFile.mkdirs()
orig.copyTo(target)
if (orig.name.endsWith(".gradle") || orig.name.endsWith(".gradle.kts")) { if (orig.name.endsWith(".gradle") || orig.name.endsWith(".gradle.kts")) {
val origContent = orig.readText() testEnvironment.replacePlaceholdersInFile(target)
var newContent = origContent
.replace("COMPOSE_GRADLE_PLUGIN_VERSION_PLACEHOLDER", testEnvironment.composeGradlePluginVersion)
.replace("KOTLIN_VERSION_PLACEHOLDER", testEnvironment.kotlinVersion)
if (testEnvironment.composeCompilerArtifact != null) {
newContent = newContent.replace("COMPOSE_COMPILER_ARTIFACT_PLACEHOLDER", testEnvironment.composeCompilerArtifact)
}
target.writeText(newContent)
} else {
orig.copyTo(target)
} }
} }
} }

1
gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProjects.kt

@ -20,6 +20,7 @@ object TestProjects {
const val defaultArgsOverride = "application/defaultArgsOverride" const val defaultArgsOverride = "application/defaultArgsOverride"
const val unpackSkiko = "application/unpackSkiko" const val unpackSkiko = "application/unpackSkiko"
const val resources = "application/resources" const val resources = "application/resources"
const val customJavaHome = "application/customJavaHome"
const val jsMpp = "misc/jsMpp" const val jsMpp = "misc/jsMpp"
const val jvmPreview = "misc/jvmPreview" const val jvmPreview = "misc/jvmPreview"
} }

34
gradle-plugins/compose/src/test/test-projects/application/customJavaHome/build.gradle

@ -0,0 +1,34 @@
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
plugins {
id "org.jetbrains.kotlin.jvm"
id "org.jetbrains.compose"
}
repositories {
jetbrainsCompose()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib"
implementation compose.desktop.currentOs
}
compose.desktop {
application {
mainClass = "MainKt"
nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageVersion = "1.0.0"
packageName = "TestPackage"
description = "Test description"
copyright = "Test Copyright Holder"
vendor = "Test Vendor"
javaHome = javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(CUSTOM_JAVA_TOOLCHAIN_VERSION_PLACEHOLDER))
}.get().metadata.installationPath.asFile.absolutePath
}
}
}

11
gradle-plugins/compose/src/test/test-projects/application/customJavaHome/settings.gradle

@ -0,0 +1,11 @@
pluginManagement {
plugins {
id 'org.jetbrains.kotlin.jvm' version 'KOTLIN_VERSION_PLACEHOLDER'
id 'org.jetbrains.compose' version 'COMPOSE_GRADLE_PLUGIN_VERSION_PLACEHOLDER'
}
repositories {
mavenLocal()
gradlePluginPortal()
}
}
rootProject.name = "simple"

18
gradle-plugins/compose/src/test/test-projects/application/customJavaHome/src/main/kotlin/main.kt

@ -0,0 +1,18 @@
import androidx.compose.material.Text
import androidx.compose.material.Button
import androidx.compose.material.MaterialTheme
import androidx.compose.ui.window.singleWindowApplication
import androidx.compose.runtime.*
fun main() = singleWindowApplication {
val scope = rememberCoroutineScope()
var text by remember { mutableStateOf("Hello, World!") }
MaterialTheme {
Button(onClick = {
text = "Hello, Desktop!"
}) {
Text(text)
}
}
}
Loading…
Cancel
Save