diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BuildReportsIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BuildReportsIT.kt index 6f57743f8a1..76eaee46ddf 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BuildReportsIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/BuildReportsIT.kt @@ -280,10 +280,7 @@ class BuildReportsIT : KGPBaseTest() { ) { val lookupsTab = projectPath.resolve("build/kotlin/compileKotlin/cacheable/caches-jvm/lookups/lookups.tab") - fun kotlinErrorPath() = tempDir - .resolve("projects-1") - .findInPath("errors") - ?: throw IllegalStateException("Could not find global Kotlin errors directory!") + fun kotlinErrorPath() = tempDir.inProjectsPersistentCache("errors") buildGradle.appendText( """ @@ -334,10 +331,7 @@ class BuildReportsIT : KGPBaseTest() { gradleVersion = gradleVersion, buildOptions = defaultBuildOptions.copy(kotlinUserHome = tempDir) ) { - fun kotlinErrorPath() = tempDir - .resolve("projects-1") - .findInPath("errors") - ?: throw IllegalStateException("Could not find global Kotlin errors directory!") + fun kotlinErrorPath() = tempDir.inProjectsPersistentCache("errors") build("compileKotlin", buildOptions = defaultBuildOptions.copy(logLevel = LogLevel.DEBUG)) { assertOutputDoesNotContain("errors were stored into file") diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/CommonizerIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/CommonizerIT.kt index 292876ad74a..5eeb08a3f23 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/CommonizerIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/CommonizerIT.kt @@ -176,9 +176,7 @@ open class CommonizerIT : KGPBaseTest() { configureCommonizerTargets() - fun expectedOutputDirectoryForIde(): Path = tempDir - .resolve("projects-1") - .findInPath("commonizer") ?: throw IllegalStateException("Failed to find 'commonizer' directory!") + fun expectedOutputDirectoryForIde(): Path = tempDir.inProjectsPersistentCache("commonizer") val expectedOutputDirectoryForBuild = projectPath.resolve("build/classes/kotlin/commonizer") @@ -551,9 +549,7 @@ open class CommonizerIT : KGPBaseTest() { configureCommonizerTargets() - fun expectedOutputDirectoryForIde(): Path = tempDir - .resolve("projects-1") - .findInPath("commonizer") ?: throw IllegalStateException("Failed to find 'commonizer' directory!") + fun expectedOutputDirectoryForIde(): Path = tempDir.inProjectsPersistentCache("commonizer") build(":copyCommonizeCInteropForIde") { assertTasksExecuted(":cinteropCurlTargetB") diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/SimpleKotlinGradleIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/SimpleKotlinGradleIT.kt index e63cdf56c31..c5091b2f9f5 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/SimpleKotlinGradleIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/SimpleKotlinGradleIT.kt @@ -6,8 +6,11 @@ import org.gradle.util.GradleVersion import org.jetbrains.kotlin.gradle.tasks.KotlinCompilerExecutionStrategy import org.jetbrains.kotlin.gradle.testbase.* import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.io.TempDir +import java.nio.file.Path import java.util.zip.ZipFile import kotlin.io.path.* +import kotlin.test.assertEquals @JvmGradlePluginTests @DisplayName("KGP simple tests") @@ -289,4 +292,35 @@ class SimpleKotlinGradleIT : KGPBaseTest() { } } } + + @DisplayName("Possible to override kotlin.user.home location") + @GradleTest + fun overrideKotlinUserHome( + gradleVersion: GradleVersion, + @TempDir tempDir: Path, + ) { + project( + projectName = "simpleProject", + gradleVersion = gradleVersion, + buildOptions = defaultBuildOptions.copy(kotlinUserHome = null) + ) { + gradleProperties.appendText( + """ + | + |kotlin.user.home=${tempDir.absolutePathString().normalizePath()} + """.trimMargin() + ) + + build("compileKotlin") { + assertTasksExecuted(":compileKotlin") + + val baseProjectsDir = tempDir.resolve("projects-1") + assertDirectoryExists(baseProjectsDir) + val projectsDirs = baseProjectsDir.listDirectoryEntries() + assertEquals(1, projectsDirs.size, message = "More then 1 child! Actual content ${projectsDirs.joinToString { it.pathString }}") + assertDirectoryExists(projectsDirs.first().resolve("sessions")) + assertDirectoryExists(projectsDirs.first().resolve("errors")) + } + } + } } diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/testbase/pathHelpers.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/testbase/pathHelpers.kt index 650f832f16f..d829d1950d5 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/testbase/pathHelpers.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/testbase/pathHelpers.kt @@ -120,3 +120,21 @@ fun Path.getSingleFileInDir(relativePath: String): Path { } } +/** + * Get a path for per-project persistent cache directory from this base persistent cache directory. + */ +fun Path.projectsPersistentCache() = resolve("projects-1") + +/** + * Searches for the specified directory in the projects persistent cache. + * + * @param directoryName The name of the directory to search for. + * @return The path of the directory if found. + * + * @throws IllegalStateException if the directory does not exist in the projects cache. Usually they are populated after some build. + */ +fun Path.inProjectsPersistentCache( + directoryName: String +) = projectsPersistentCache().findInPath(directoryName) + ?: throw IllegalStateException("$directoryName does not exist in the projects cache under ${this.absolutePathString()}") +