Repository: JetBrains/compose-multiplatform
File: gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/ComposeCompilerKotlinSupportPlugin.kt (Kotlin)

Code before:

    private fun collectUnsupportedCompilerPluginUsages(target: Project) {
        fun Project.hasNonJvmTargets(): Boolean {
            val nonJvmTargets = setOf(KotlinPlatformType.native, KotlinPlatformType.js, KotlinPlatformType.wasm)
            return mppExtOrNull?.targets?.any {
                it.platformType in nonJvmTargets
            } ?: false
        }

        fun SubpluginArtifact.isNonJBComposeCompiler(): Boolean {
            return !groupId.startsWith("org.jetbrains.compose.compiler")
        }

        val service = ComposeMultiplatformBuildService.provider(target)
        buildEventsListenerRegistry.onTaskCompletion(service)

        val providedService = try {
            service.get()
        } catch (e: ClassCastException) {
            // Compose Gradle plugin was probably loaded more than once
            // See https://github.com/JetBrains/compose-multiplatform/issues/3459

            throw IllegalStateException(
                "Failed to get ComposeMultiplatformBuildService instance." +
                        " Compose Gradle plugin was probably loaded more than once." +
                        " Consider declaring it in the root build.gradle.kts. Original exception message: ${e.message}",
                e
            )
        }

        providedService.parameters.unsupportedCompilerPlugins.add(
            target.provider {
                composeCompilerArtifactProvider.compilerArtifact.takeIf {
                    target.hasNonJvmTargets() && it.isNonJBComposeCompiler()
                }
            }
        )
    }

    override fun getCompilerPluginId(): String =
        "androidx.compose.compiler.plugins.kotlin"

    override fun getPluginArtifact(): SubpluginArtifact =
        composeCompilerArtifactProvider.compilerArtifact

    override fun getPluginArtifactForNative(): SubpluginArtifact =
        composeCompilerArtifactProvider.compilerHostedArtifact

    override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean =
        when (kotlinCompilation.target.platformType) {
            KotlinPlatformType.common -> true

Review comment (suggestion):
I'm not sure "Original exception message" is necessary.
`--stacktrace` or `--full-stacktrace` will print the nested exception.

Code after:

    private fun collectUnsupportedCompilerPluginUsages(target: Project) {
        fun Project.hasNonJvmTargets(): Boolean {
            val nonJvmTargets = setOf(KotlinPlatformType.native, KotlinPlatformType.js, KotlinPlatformType.wasm)
            return mppExtOrNull?.targets?.any {
                it.platformType in nonJvmTargets
            } ?: false
        }

        fun SubpluginArtifact.isNonJBComposeCompiler(): Boolean {
            return !groupId.startsWith("org.jetbrains.compose.compiler")
        }

        val service = ComposeMultiplatformBuildService.provider(target)
        buildEventsListenerRegistry.onTaskCompletion(service)

        val providedService = try {
            service.get()
        } catch (e: ClassCastException) {
            // Compose Gradle plugin was probably loaded more than once
            // See https://github.com/JetBrains/compose-multiplatform/issues/3459

            throw IllegalStateException(
                "Failed to get ComposeMultiplatformBuildService instance." +
                        " Compose Gradle plugin was probably loaded more than once." +
                        " Consider declaring it in the root build.gradle.kts",
                e
            )
        }

        providedService.parameters.unsupportedCompilerPlugins.add(
            target.provider {
                composeCompilerArtifactProvider.compilerArtifact.takeIf {
                    target.hasNonJvmTargets() && it.isNonJBComposeCompiler()
                }
            }
        )
    }

    override fun getCompilerPluginId(): String =
        "androidx.compose.compiler.plugins.kotlin"

    override fun getPluginArtifact(): SubpluginArtifact =
        composeCompilerArtifactProvider.compilerArtifact

    override fun getPluginArtifactForNative(): SubpluginArtifact =
        composeCompilerArtifactProvider.compilerHostedArtifact

    override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean =
        when (kotlinCompilation.target.platformType) {
            KotlinPlatformType.common -> true