Repository: Kotlin/kotlinx.coroutines
File: integration-testing/build.gradle.kts (Kotlin)

Code before:
    }

    create<Test>("javaConsumersTest") {
        val sourceSet = sourceSets[name]
        testClassesDirs = sourceSet.output.classesDirs
        classpath = sourceSet.runtimeClasspath
    }

    // In this test coroutine debug agent is attached as a javaagent vm argument
    // to a pure Java project (safeDebugAgentTest) with no Kotlin stdlib dependency.
    // In this case the error should be thrown from AgetnPremain class:
    // "java.lang.IllegalStateException: kotlinx.coroutines debug agent failed to load."
    val safeDebugAgentTest = create<Exec>("safeDebugAgentTest") {
        // take kotlinx-coroutines-core.jar from a sourceSet with coroutines dependency
        val sourceSet = sourceSets["coreAgentTest"]
        val coroutinesDebugJar = sourceSet.runtimeClasspath.filter {
            it.name == "kotlinx-coroutines-core-jvm-$coroutinesVersion.jar"
        }.singleFile

        commandLine(
            if (System.getProperty("os.name").toLowerCase().contains("windows"))
                "gradlew.bat"
            else
                "./gradlew",
            ":safeDebugAgentTest:run",
            "-Pdebug.agent=${coroutinesDebugJar.absolutePath}"
        )

        isIgnoreExitValue = true
        errorOutput = ByteArrayOutputStream()
        standardOutput = ByteArrayOutputStream()

        doLast {
            val expectedOutput = "OK!"
            val expectedAgentError =
                "kotlinx.coroutines debug agent failed to load and was not attached.\n" +
                    "Please ensure that the Kotlin standard library is present in the classpath.\n" +
                    "Alternatively, you can disable kotlinx.coroutines debug agent by removing `-javaagent=/path/kotlinx-coroutines-core.jar` from your VM arguments.\n"
            val actualOutput = standardOutput.toString()
            val actualError = errorOutput.toString()
            if (!actualOutput.contains(expectedOutput)) {
                throw GradleException("Expected \"OK!\" in the output of ':safeDebugAgentTest:run' but got:\n" + actualOutput + "\n" + actualError)
            }
            if (!actualError.contains(expectedAgentError)) {
                throw GradleException("':safeDebugAgentTest:run' has an unexpected error output: \n" + actualError)
            }
        }
    }

    check {
        dependsOn(

Review comment (suggestion):
`kotlinx.coroutines` is used in compiler integration tests, where additional parameters are passed to Gradle to indicate which compiler version to use, among other things. This command-line invocation can occasionally break in that scenario: imagine that `kotlinx.coroutines` uses `2.2.0`, but someone tests `kotlinx.coroutines` with `2.4.0-Beta`. The locally published `kotlinx-coroutines-core` JAR will be compiled by `2.4.0-Beta`, but this invocation will still use 2.2.0, which is a mismatch prohibited by the compiler (more than one major version).

Code after:
        System.setProperty("coroutines.debug.agent.path", coroutinesDebugJar.absolutePath) // todo: fixme
    }

    create<Test>("javaConsumersTest") {
        val sourceSet = sourceSets[name]
        testClassesDirs = sourceSet.output.classesDirs
        classpath = sourceSet.runtimeClasspath
    }

    check {
        dependsOn(
            "jvmCoreTest",
            "debugDynamicAgentTest",
            "mavenTest",
            "debugAgentTest",
            "coreAgentTest",
            "javaConsumersTest",
            ":jpmsTest:check",
            "smokeTest:build",
            "java8Test:check",
            "safeDebugAgentTest:runWithExpectedFailure"
        )
    }

    // Drop this when node js version become stable
    withType(KotlinNpmInstallTask::class.java).configureEach {
        args.add("--ignore-engines")
    }

    withType(KotlinJvmCompile::class.java).configureEach {
        jvmTargetValidationMode = JvmTargetValidationMode.WARNING
    }
}