diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/configureJvmApplication.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/configureJvmApplication.kt index 13e30ade3c..01fae60244 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/configureJvmApplication.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/internal/configureJvmApplication.kt @@ -58,7 +58,6 @@ private fun JvmApplicationContext.configureCommonJvmDesktopTasks(): CommonJvmDes taskNameObject = "runtime" ) { javaHome.set(app.javaHomeProvider) - javaRuntimePropertiesFile.set(jvmTmpDirForTask().file("properties.bin")) } val suggestRuntimeModules = tasks.register( diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractCheckNativeDistributionRuntime.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractCheckNativeDistributionRuntime.kt index 953c00c704..b729dc0cdf 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractCheckNativeDistributionRuntime.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractCheckNativeDistributionRuntime.kt @@ -6,6 +6,7 @@ package org.jetbrains.compose.desktop.application.tasks import org.gradle.api.file.Directory +import org.gradle.api.file.RegularFile import org.gradle.api.file.RegularFileProperty import org.gradle.api.provider.Property import org.gradle.api.provider.Provider @@ -23,14 +24,17 @@ internal const val MIN_JAVA_RUNTIME_VERSION = 15 @CacheableTask abstract class AbstractCheckNativeDistributionRuntime : AbstractComposeDesktopTask() { - @get:Input + @get:PathSensitive(PathSensitivity.ABSOLUTE) + @get:InputDirectory val javaHome: Property = objects.notNullProperty() + private val taskDir = project.layout.buildDirectory.dir("compose/tmp/$name") + @get:OutputFile - val javaRuntimePropertiesFile: RegularFileProperty = objects.fileProperty() + val javaRuntimePropertiesFile: Provider = taskDir.map { it.file("properties.bin") } @get:LocalState - val workingDir: Provider = project.layout.buildDirectory.dir("compose/tmp/$name") + val workingDir: Provider = taskDir.map { it.dir("localState") } private val javaExec: File get() = getTool("java") @@ -47,6 +51,8 @@ abstract class AbstractCheckNativeDistributionRuntime : AbstractComposeDesktopTa @TaskAction fun run() { + taskDir.ioFile.mkdirs() + val javaRuntimeVersion = try { getJavaRuntimeVersionUnsafe()?.toIntOrNull() ?: -1 } catch (e: Exception) { diff --git a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/DesktopApplicationTest.kt b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/DesktopApplicationTest.kt index 4d396344e1..3f0d3b7b57 100644 --- a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/DesktopApplicationTest.kt +++ b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/DesktopApplicationTest.kt @@ -122,6 +122,32 @@ class DesktopApplicationTest : GradlePluginTestBase() { testPackageJvmDistributions() } + @Test + fun gradleBuildCache() = with(testProject(TestProjects.jvm)) { + modifyGradleProperties { + setProperty("org.gradle.caching", "true") + } + modifyTextFile("settings.gradle") { + it + "\n" + """ + buildCache { + local { + directory = new File(rootDir, 'build-cache') + } + } + """.trimIndent() + } + + val packagingTask = ":packageDistributionForCurrentOS" + gradle(packagingTask).build().checks { check -> + check.taskOutcome(packagingTask, TaskOutcome.SUCCESS) + } + + gradle("clean", packagingTask).build().checks { check -> + check.taskOutcome(":checkRuntime", TaskOutcome.FROM_CACHE) + check.taskOutcome(packagingTask, TaskOutcome.SUCCESS) + } + } + @Test fun packageMpp() = with(testProject(TestProjects.mpp)) { testPackageJvmDistributions() diff --git a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProject.kt b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProject.kt index 3aec18114e..8b03870f42 100644 --- a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProject.kt +++ b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/utils/TestProject.kt @@ -8,6 +8,7 @@ package org.jetbrains.compose.test.utils import org.gradle.testkit.runner.GradleRunner import org.jetbrains.compose.desktop.application.internal.ComposeProperties import java.io.File +import java.util.Properties data class TestEnvironment( val workingDir: File, @@ -77,5 +78,29 @@ class TestProject( fun file(path: String): File = testEnvironment.workingDir.resolve(path) + + fun modifyTextFile(path: String, fn: (String) -> String) { + val file = file(path) + val oldContent = file.readText() + val newContent = fn(oldContent) + file.writeText(newContent) + } + fun modifyGradleProperties(fn: Properties.() -> Unit) { + val propertiesFile = file("gradle.properties") + val properties = Properties() + if (propertiesFile.exists()) { + propertiesFile.bufferedReader().use { reader -> + properties.load(reader) + } + } + fn(properties) + propertiesFile.delete() + + if (properties.isNotEmpty()) { + propertiesFile.bufferedWriter().use { writer -> + properties.store(writer, null) + } + } + } }