diff --git a/burst-gradle-plugin/build.gradle.kts b/burst-gradle-plugin/build.gradle.kts index db95c99..a1baebb 100644 --- a/burst-gradle-plugin/build.gradle.kts +++ b/burst-gradle-plugin/build.gradle.kts @@ -4,6 +4,7 @@ import com.vanniktech.maven.publish.MavenPublishBaseExtension plugins { id("java-gradle-plugin") + `kotlin-dsl` kotlin("jvm") id("com.github.gmazzo.buildconfig") id("org.jetbrains.dokka") diff --git a/burst-gradle-plugin/src/main/kotlin/app/cash/burst/gradle/BurstPlugin.kt b/burst-gradle-plugin/src/main/kotlin/app/cash/burst/gradle/BurstPlugin.kt index 1656de4..0c4b0a0 100644 --- a/burst-gradle-plugin/src/main/kotlin/app/cash/burst/gradle/BurstPlugin.kt +++ b/burst-gradle-plugin/src/main/kotlin/app/cash/burst/gradle/BurstPlugin.kt @@ -15,9 +15,18 @@ */ package app.cash.burst.gradle +import app.cash.burst.gradle.BuildConfig.burstVersion +import org.gradle.api.Project import org.gradle.api.provider.Provider +import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.dependencies +import org.gradle.kotlin.dsl.invoke +import org.gradle.kotlin.dsl.withType +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerPluginSupportPlugin +import org.jetbrains.kotlin.gradle.plugin.KotlinMultiplatformPluginWrapper +import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact import org.jetbrains.kotlin.gradle.plugin.SubpluginOption @@ -33,6 +42,30 @@ class BurstPlugin : KotlinCompilerPluginSupportPlugin { version = BuildConfig.KOTLIN_PLUGIN_VERSION, ) + override fun apply(target: Project) { + super.apply(target) + + // kotlin("multiplatform") targeting Java platforms. + target.plugins.withType { + target.configure { + sourceSets { + commonTest { + dependencies { + implementation("app.cash.burst:burst:$burstVersion") + } + } + } + } + } + + // kotlin("jvm") + target.plugins.withType { + target.dependencies { + add("testImplementation", "app.cash.burst:burst:$burstVersion") + } + } + } + override fun applyToCompilation( kotlinCompilation: KotlinCompilation<*>, ): Provider> { diff --git a/burst-gradle-plugin/src/test/kotlin/app/cash/burst/gradle/BurstGradlePluginTest.kt b/burst-gradle-plugin/src/test/kotlin/app/cash/burst/gradle/BurstGradlePluginTest.kt index 3506724..586c691 100644 --- a/burst-gradle-plugin/src/test/kotlin/app/cash/burst/gradle/BurstGradlePluginTest.kt +++ b/burst-gradle-plugin/src/test/kotlin/app/cash/burst/gradle/BurstGradlePluginTest.kt @@ -28,8 +28,8 @@ import org.junit.Test class BurstGradlePluginTest { @Test - fun happyPath() { - val projectDir = File("src/test/projects/basic") + fun multiplatform() { + val projectDir = File("src/test/projects/multiplatform") val taskName = ":lib:jvmTest" val result = createRunner(projectDir, "clean", taskName).build() @@ -61,6 +61,40 @@ class BurstGradlePluginTest { assertThat(sampleVariant.skipped).isFalse() } + @Test + fun jvm() { + val projectDir = File("src/test/projects/jvm") + + val taskName = ":lib:test" + val result = createRunner(projectDir, "clean", taskName).build() + assertThat(SUCCESS_OUTCOMES) + .contains(result.task(taskName)!!.outcome) + + val testResults = projectDir.resolve("lib/build/test-results") + val testXmlFile = testResults.resolve("test/TEST-CoffeeTest.xml") + + val testSuite = readTestSuite(testXmlFile) + + assertThat(testSuite.testCases.map { it.name }).containsExactlyInAnyOrder( + "test", + "test_Decaf_Oat", + "test_Regular_Milk", + "test_Regular_None", + "test_Decaf_Milk", + "test_Decaf_None", + "test_Double_Milk", + "test_Double_None", + "test_Regular_Oat", + "test_Double_Oat", + ) + + val originalTest = testSuite.testCases.single { it.name == "test" } + assertThat(originalTest.skipped).isTrue() + + val sampleVariant = testSuite.testCases.single { it.name == "test_Decaf_Oat" } + assertThat(sampleVariant.skipped).isFalse() + } + private fun createRunner( projectDir: File, vararg taskNames: String, diff --git a/burst-gradle-plugin/src/test/projects/basic/build.gradle.kts b/burst-gradle-plugin/src/test/projects/jvm/build.gradle.kts similarity index 100% rename from burst-gradle-plugin/src/test/projects/basic/build.gradle.kts rename to burst-gradle-plugin/src/test/projects/jvm/build.gradle.kts diff --git a/burst-gradle-plugin/src/test/projects/jvm/lib/build.gradle.kts b/burst-gradle-plugin/src/test/projects/jvm/lib/build.gradle.kts new file mode 100644 index 0000000..36cb092 --- /dev/null +++ b/burst-gradle-plugin/src/test/projects/jvm/lib/build.gradle.kts @@ -0,0 +1,8 @@ +plugins { + kotlin("jvm") + id("app.cash.burst") +} + +dependencies { + testImplementation(kotlin("test")) +} diff --git a/burst-gradle-plugin/src/test/projects/basic/lib/src/commonTest/kotlin/CoffeeTest.kt b/burst-gradle-plugin/src/test/projects/jvm/lib/src/test/kotlin/CoffeeTest.kt similarity index 100% rename from burst-gradle-plugin/src/test/projects/basic/lib/src/commonTest/kotlin/CoffeeTest.kt rename to burst-gradle-plugin/src/test/projects/jvm/lib/src/test/kotlin/CoffeeTest.kt diff --git a/burst-gradle-plugin/src/test/projects/basic/settings.gradle.kts b/burst-gradle-plugin/src/test/projects/jvm/settings.gradle.kts similarity index 100% rename from burst-gradle-plugin/src/test/projects/basic/settings.gradle.kts rename to burst-gradle-plugin/src/test/projects/jvm/settings.gradle.kts diff --git a/burst-gradle-plugin/src/test/projects/multiplatform/build.gradle.kts b/burst-gradle-plugin/src/test/projects/multiplatform/build.gradle.kts new file mode 100644 index 0000000..dae8c15 --- /dev/null +++ b/burst-gradle-plugin/src/test/projects/multiplatform/build.gradle.kts @@ -0,0 +1,23 @@ +buildscript { + repositories { + maven { + url = file("$rootDir/../../../../../build/testMaven").toURI() + } + mavenCentral() + google() + } + dependencies { + classpath("app.cash.burst:burst-gradle-plugin:${project.property("burstVersion")}") + classpath(libs.kotlin.gradle.plugin) + } +} + +allprojects { + repositories { + maven { + url = file("$rootDir/../../../../../build/testMaven").toURI() + } + mavenCentral() + google() + } +} diff --git a/burst-gradle-plugin/src/test/projects/basic/lib/build.gradle.kts b/burst-gradle-plugin/src/test/projects/multiplatform/lib/build.gradle.kts similarity index 69% rename from burst-gradle-plugin/src/test/projects/basic/lib/build.gradle.kts rename to burst-gradle-plugin/src/test/projects/multiplatform/lib/build.gradle.kts index 294ab7d..c16da92 100644 --- a/burst-gradle-plugin/src/test/projects/basic/lib/build.gradle.kts +++ b/burst-gradle-plugin/src/test/projects/multiplatform/lib/build.gradle.kts @@ -9,7 +9,6 @@ kotlin { sourceSets { commonTest { dependencies { - implementation("app.cash.burst:burst:${project.property("burstVersion")}") implementation(kotlin("test")) } } diff --git a/burst-gradle-plugin/src/test/projects/multiplatform/lib/src/commonTest/kotlin/CoffeeTest.kt b/burst-gradle-plugin/src/test/projects/multiplatform/lib/src/commonTest/kotlin/CoffeeTest.kt new file mode 100644 index 0000000..d305ba5 --- /dev/null +++ b/burst-gradle-plugin/src/test/projects/multiplatform/lib/src/commonTest/kotlin/CoffeeTest.kt @@ -0,0 +1,16 @@ +import app.cash.burst.Burst +import kotlin.test.Test + +@Burst +class CoffeeTest { + val log = mutableListOf() + + @Test + fun test(espresso: Espresso, dairy: Dairy) { + log += "running $espresso $dairy" + } +} + +enum class Espresso { Decaf, Regular, Double } + +enum class Dairy { None, Milk, Oat } diff --git a/burst-gradle-plugin/src/test/projects/multiplatform/settings.gradle.kts b/burst-gradle-plugin/src/test/projects/multiplatform/settings.gradle.kts new file mode 100644 index 0000000..78eeed4 --- /dev/null +++ b/burst-gradle-plugin/src/test/projects/multiplatform/settings.gradle.kts @@ -0,0 +1,9 @@ +dependencyResolutionManagement { + versionCatalogs { + create("libs") { + from(files("../../../../../gradle/libs.versions.toml")) + } + } +} + +include(":lib")