Repository: JetBrains/kotlin
File: libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/AbstractKotlinAndroidGradleTests.kt (Kotlin)

Code before:
        gradleBuildScript("Lib").appendText(
            "\ndependencies { implementation(project(':sample-lib')) }"
        )
        val lintTask = ":Lib:lintFlavor1Debug"
        build(lintTask) {
            assertSuccessful()
            assertTasksExecuted(lintTask) // Check that the lint task ran successfully, KT-27170
        }
    }

    @Test
    fun testJvmWithJava() = with(Project("mppJvmWithJava")) {
        setupWorkingDir()

        build("build") {
            assertSuccessful()
        }

        build("assemble") {
            assertSuccessful()
        }
    }

    @Test
    fun testJvmWithJavaConfigurationCache() =
        with(Project("mppJvmWithJava", gradleVersionRequirement = GradleVersionRequired.AtLeast("7.1"))) {
            setupWorkingDir()

            build("jar", options = defaultBuildOptions().copy(configurationCache = true)) {
                assertSuccessful()
            }

            build("jar", options = defaultBuildOptions().copy(configurationCache = true)) {
                assertSuccessful()
                assertContains("Reusing configuration cache.")
            }
        }
}

open class KotlinAndroid70GradleIT : KotlinAndroid36GradleIT() {
    override val androidGradlePluginVersion: AGPVersion
        get() = AGPVersion.v7_0_0

    override val defaultGradleVersion: GradleVersionRequired
        get() = GradleVersionRequired.AtLeast("7.0")

    override fun defaultBuildOptions(): BuildOptions {
        val javaHome = File("/opt/openjdk-bin-11")
        Assume.assumeTrue("JDK 11 should be available", javaHome.isDirectory)
        return super.defaultBuildOptions().copy(javaHome = javaHome, warningMode = WarningMode.Summary)
    }

Review comment (suggestion):
This test is not related to Android support, so putting it in `KotlinAndroid36GradleIT` doesn't look right, especially since this test will run more than once: here and in the subtype `KotlinAndroid70GradleIT` with a different AGP version.

Code after:

    @Test
    fun testLintInAndroidProjectsDependingOnMppWithoutAndroid() = with(Project("AndroidProject")) {
        embedProject(Project("sample-lib", directoryPrefix = "new-mpp-lib-and-app"))
        gradleBuildScript("Lib").appendText(
            "\ndependencies { implementation(project(':sample-lib')) }"
        )
        val lintTask = ":Lib:lintFlavor1Debug"
        build(lintTask) {
            assertSuccessful()
            assertTasksExecuted(lintTask) // Check that the lint task ran successfully, KT-27170
        }
    }

    @Test
    fun testJvmWithJava() = with(Project("mppJvmWithJava")) {
        setupWorkingDir()

        build("build") {
            assertSuccessful()
        }

        build("assemble") {
            assertSuccessful()
        }
    }

    @Test
    fun `test KotlinToolingMetadataArtifact is bundled into apk`(): Unit = with(Project("kotlinToolingMetadataAndroid")) {
        build("assembleDebug") {
            assertSuccessful()
            assertTasksNotExecuted(":${BuildKotlinToolingMetadataTask.defaultTaskName}")

            val debugApk = project.projectDir.resolve("build/outputs/apk/debug/project-debug.apk")
            assertTrue(debugApk.exists(), "Missing debug apk ${debugApk.path}")
            ZipFile(debugApk).use { zip ->
                assertNull(zip.getEntry("kotlin-tooling-metadata.json"), "Expected metadata *not* being packaged into debug apk")
            }
        }

        build("assembleRelease") {
            assertSuccessful()
            assertTasksExecuted(":${BuildKotlinToolingMetadataTask.defaultTaskName}")
            val releaseApk = project.projectDir.resolve("build/outputs/apk/release/project-release-unsigned.apk")

            assertTrue(releaseApk.exists(), "Missing release apk ${releaseApk.path}")
            ZipFile(releaseApk).use { zip ->
                assertNotNull(zip.getEntry("kotlin-tooling-metadata.json"), "Expected metadata being packaged into release apk")
            }
        }
    }