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

Code before:
    private fun jdkDistributionProbingError(errorMessage: String): Nothing {
        val fullErrorMessage = buildString {
            appendLine("Failed to check JDK distribution: $errorMessage")
            appendLine("JDK distribution path: ${jdkHomeFile.absolutePath}")
        }
        error(fullErrorMessage)
    }

    @TaskAction
    fun run() {
        taskDir.ioFile.mkdirs()

        val jdkHome = jdkHomeFile
        val javaExecutable = jdkHome.getJdkTool("java")
        val javacExecutable = jdkHome.getJdkTool("javac")

        val jvmRuntimeVersionString = getJavaRuntimeVersion(
            javaExecutable = javaExecutable,
            javacExecutable = javacExecutable
        )

        val jvmRuntimeVersion = jvmRuntimeVersionString?.toIntOrNull()
            ?: jdkDistributionProbingError("JDK version '$jvmRuntimeVersionString' has unexpected format")

        check(jvmRuntimeVersion >= MIN_JAVA_RUNTIME_VERSION) {
            jdkDistributionProbingError(
                "minimum required JDK version is '$MIN_JAVA_RUNTIME_VERSION', " +
                "but actual version is '$jvmRuntimeVersion'"
            )
        }

        val modules = arrayListOf<String>()
        runExternalTool(
            tool = javaExecutable,
            args = listOf("--list-modules"),
            logToConsole = ExternalToolRunner.LogToConsole.Never,
            processStdout = { stdout ->
                stdout.lineSequence().forEach { line ->
                    val moduleName = line.trim().substringBefore("@")
                    if (moduleName.isNotBlank()) {
                        modules.add(moduleName)
                    }
                }
            }
        )

        val properties = JvmRuntimeProperties(jvmRuntimeVersion, modules)
        JvmRuntimeProperties.writeToFile(properties, javaRuntimePropertiesFile.ioFile)
    }

    private fun getJavaRuntimeVersion(

Review comment (suggestion):
Applying it to `System.getProperty("java.version")` doesn't seem right because it might contain something like `11.0.4`

Code after:
        if (missingTools.size == 1) jdkDistributionProbingError("${missingTools.single()} is missing")

        jdkDistributionProbingError("${missingTools.joinToString(", ")} are missing")
    }

    private fun jdkDistributionProbingError(errorMessage: String): Nothing {
        val fullErrorMessage = buildString {
            appendLine("Failed to check JDK distribution: $errorMessage")
            appendLine("JDK distribution path: ${jdkHomeFile.absolutePath}")
        }
        error(fullErrorMessage)
    }

    @TaskAction
    fun run() {
        taskDir.ioFile.mkdirs()

        val jdkHome = jdkHomeFile
        val javaExecutable = jdkHome.getJdkTool("java")
        val jlinkExecutable = jdkHome.getJdkTool("jlink")
        val jpackageExecutabke = jdkHome.getJdkTool("jpackage")
        ensureToolsExist(javaExecutable, jlinkExecutable, jpackageExecutabke)

        val jvmRuntimeVersionString = getJavaRuntimeVersion(javaExecutable)

        val jvmRuntimeVersion = jvmRuntimeVersionString?.toIntOrNull()
            ?: jdkDistributionProbingError("JDK version '$jvmRuntimeVersionString' has unexpected format")

        check(jvmRuntimeVersion >= MIN_JAVA_RUNTIME_VERSION) {
            jdkDistributionProbingError(
                "minimum required JDK version is '$MIN_JAVA_RUNTIME_VERSION', " +
                "but actual version is '$jvmRuntimeVersion'"
            )
        }

        val modules = arrayListOf<String>()
        runExternalTool(
            tool = javaExecutable,
            args = listOf("--list-modules"),
            logToConsole = ExternalToolRunner.LogToConsole.Never,
            processStdout = { stdout ->
                stdout.lineSequence().forEach { line ->
                    val moduleName = line.trim().substringBefore("@")
                    if (moduleName.isNotBlank()) {
                        modules.add(moduleName)
                    }
                }
            }
        )

        val properties = JvmRuntimeProperties(jvmRuntimeVersion, modules)