[Build] Fix configuration cache issue in KGP IT

`project` cannot be used at execution time.
^KTI-1433 Fixed
This commit is contained in:
Alexander.Likhachev
2023-10-20 14:29:33 +02:00
committed by Space Team
parent fa89b8b0f1
commit f630a27f14
@@ -341,6 +341,7 @@ tasks.withType<Test> {
val jdk11Provider = project.getToolchainJdkHomeFor(JdkMajorVersion.JDK_11_0)
val jdk16Provider = project.getToolchainJdkHomeFor(JdkMajorVersion.JDK_16_0)
val jdk17Provider = project.getToolchainJdkHomeFor(JdkMajorVersion.JDK_17_0)
val jdk21Provider = project.getToolchainJdkHomeFor(JdkMajorVersion.JDK_21_0)
val mavenLocalRepo = project.providers.systemProperty("maven.repo.local").orNull
// Query required JDKs paths only on execution phase to avoid triggering auto-download on project configuration phase
@@ -352,12 +353,7 @@ tasks.withType<Test> {
systemProperty("jdk11Home", jdk11Provider.get())
systemProperty("jdk16Home", jdk16Provider.get())
systemProperty("jdk17Home", jdk17Provider.get())
// jdk21Provider.isPresent throws NoToolchainAvailableException, so, we have to check for the exception
// Storing jdk21Provider in a field leads to "Configuration cache state could not be cached" error,
// since it tries to resolve the toolchain as well.
try {
systemProperty("jdk21Home", project.getToolchainJdkHomeFor(JdkMajorVersion.JDK_21_0).get())
} catch (_: NoToolchainAvailableException) {}
systemProperty("jdk21Home", jdk21Provider.get())
if (mavenLocalRepo != null) {
systemProperty("maven.repo.local", mavenLocalRepo)
}