Workaround for KonanTarget serialization problem.

Added a test with configuration cache to reproduce the problem
diff --git a/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KotlinFactories.kt b/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KotlinFactories.kt
index 882ded5..291dc7f 100644
--- a/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KotlinFactories.kt
+++ b/gradle-plugin/src/main/kotlin/com/google/devtools/ksp/gradle/KotlinFactories.kt
@@ -18,7 +18,6 @@
 @file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
 
 package com.google.devtools.ksp.gradle
-
 import org.gradle.api.Project
 import org.gradle.api.Task
 import org.gradle.api.file.FileCollection
@@ -44,7 +43,18 @@
 import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
 import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
 import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments
-import org.jetbrains.kotlin.gradle.dsl.*
+import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompilerOptions
+import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompilerOptionsDefault
+import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompilerOptionsHelper
+import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions
+import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptionsDefault
+import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptionsHelper
+import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformCommonCompilerOptions
+import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformCommonCompilerOptionsDefault
+import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformCommonCompilerOptionsHelper
+import org.jetbrains.kotlin.gradle.dsl.KotlinNativeCompilerOptions
+import org.jetbrains.kotlin.gradle.dsl.KotlinNativeCompilerOptionsDefault
+import org.jetbrains.kotlin.gradle.dsl.KotlinNativeCompilerOptionsHelper
 import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
 import org.jetbrains.kotlin.gradle.plugin.KotlinCompilationInfo
 import org.jetbrains.kotlin.gradle.plugin.SubpluginOption
@@ -155,10 +165,11 @@
                     )
 
                     kspTask.onlyIf {
-                        // kspTask.konanTarget.enabledOnCurrentHost
-                        // workaround for: https://github.com/google/ksp/issues/1522
+                        // KonanTarget is not properly serializable, hence we should check by name
+                        // see https://youtrack.jetbrains.com/issue/KT-61657.
+                        val konanTargetName = kspTask.konanTarget.name
                         HostManager().enabled.any {
-                            it.name == kspTask.konanTarget.name
+                            it.name == konanTargetName
                         }
                     }
                 }
diff --git a/gradle-plugin/src/test/kotlin/com/google/devtools/ksp/gradle/GradleCompilationTest.kt b/gradle-plugin/src/test/kotlin/com/google/devtools/ksp/gradle/GradleCompilationTest.kt
index a065d7c..10b5709 100644
--- a/gradle-plugin/src/test/kotlin/com/google/devtools/ksp/gradle/GradleCompilationTest.kt
+++ b/gradle-plugin/src/test/kotlin/com/google/devtools/ksp/gradle/GradleCompilationTest.kt
@@ -72,6 +72,79 @@
     }
 
     @Test
+    fun applicationCanAccessGeneratedCode_multiplatform_withConfigCache() {
+        testRule.setupAppAsMultiplatformApp(
+            """
+                kotlin {
+                    jvm { }
+                    js(IR) { browser() }
+                    linuxX64 {}
+                    macosArm64 {}
+                    androidTarget()
+                }
+            """.trimIndent()
+        )
+        val kspConfigs =
+            """configurations.matching { it.name.startsWith("ksp") && !it.name.endsWith("ProcessorClasspath") }"""
+        testRule.appModule.buildFileAdditions.add(
+            """
+                $kspConfigs.all {
+                    // Make sure ksp configs are not empty.
+                    project.dependencies.add(name, project(":${testRule.processorModule.name}"))
+                }
+            """.trimIndent()
+        )
+
+        class MyProcessor(private val codeGenerator: CodeGenerator) : SymbolProcessor {
+            var count = 0
+            override fun process(resolver: Resolver): List<KSAnnotated> {
+                /**
+                 * The source file accessing the generated code is added later to be able to test the configuration
+                 * cache and the workaround for https://youtrack.jetbrains.com/issue/KT-61657.
+                 */
+                val needToGenerate = resolver.getAllFiles().any { it.fileName == "Foo.kt" }
+                if (count == 0 && needToGenerate) {
+                    codeGenerator.createNewFile(Dependencies.ALL_FILES, "", "Generated").use {
+                        it.writer(Charsets.UTF_8).use {
+                            it.write("class ToBeGenerated")
+                        }
+                    }
+                    count += 1
+                }
+                return emptyList()
+            }
+        }
+
+        class Provider : TestSymbolProcessorProvider({ env -> MyProcessor(env.codeGenerator) })
+
+        testRule.addProvider(Provider::class)
+
+        val compileArgs = listOf(
+            "app:compileKotlinLinuxX64", "--configuration-cache", "--configuration-cache-problems=fail"
+        )
+        val runner = testRule.runner()
+        // compile, no sources, nothing will run
+        runner
+            .withArguments(compileArgs)
+            .forwardOutput()
+            .build()
+        // add a file that needs access to the generated file
+        testRule.appModule.addMultiplatformSource(
+            "commonMain", "Foo.kt",
+            """
+            class Foo {
+                val x = ToBeGenerated()
+            }
+            """.trimIndent()
+        )
+        // now compile again
+        runner
+            .withArguments(compileArgs)
+            .forwardOutput()
+            .build()
+    }
+
+    @Test
     fun applicationCanAccessGeneratedCode() {
         testRule.setupAppAsJvmApp()
         testRule.appModule.dependencies.add(
diff --git a/gradle-plugin/src/test/kotlin/com/google/devtools/ksp/gradle/ProcessorClasspathConfigurationsTest.kt b/gradle-plugin/src/test/kotlin/com/google/devtools/ksp/gradle/ProcessorClasspathConfigurationsTest.kt
index 8a0f467..713eaf4 100644
--- a/gradle-plugin/src/test/kotlin/com/google/devtools/ksp/gradle/ProcessorClasspathConfigurationsTest.kt
+++ b/gradle-plugin/src/test/kotlin/com/google/devtools/ksp/gradle/ProcessorClasspathConfigurationsTest.kt
@@ -153,7 +153,7 @@
         // trigger task creation. KSP should not resolve classpaths
         // at this step
         val buildResult = testRule.runner()
-            .withArguments(":app:tasks")
+            .withArguments(":app:tasks", "--all")
             .build()
         val taskNames = listOf(
             "kspKotlinJs",