diff --git a/build.gradle.kts b/build.gradle.kts index 6b5fd6f..3a0be09 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -22,7 +22,7 @@ buildscript { dependencies { classpath(libs.binary.compatibility.validator.gradle.plugin) classpath(libs.mavenPublish.gradle.plugin) - classpath(libs.kotlin.gradle.plugin) + classpath(libs.kotlin.gradlePlugin) classpath(libs.dokka.gradle.plugin) classpath(libs.google.ksp) } diff --git a/burst-gradle-plugin/build.gradle.kts b/burst-gradle-plugin/build.gradle.kts index 3e389c0..d74d816 100644 --- a/burst-gradle-plugin/build.gradle.kts +++ b/burst-gradle-plugin/build.gradle.kts @@ -15,7 +15,7 @@ dependencies { implementation(kotlin("gradle-plugin-api")) implementation(projects.burst) implementation(projects.burstKotlinPlugin) - implementation(libs.kotlin.gradle.plugin) + implementation(libs.kotlin.gradlePlugin) testImplementation(libs.assertk) testImplementation(libs.junit) testImplementation(libs.kotlin.test) 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 0c4b0a0..3df8df9 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 @@ -23,6 +23,7 @@ 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.KotlinAndroidPluginWrapper import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerPluginSupportPlugin import org.jetbrains.kotlin.gradle.plugin.KotlinMultiplatformPluginWrapper @@ -45,7 +46,7 @@ class BurstPlugin : KotlinCompilerPluginSupportPlugin { override fun apply(target: Project) { super.apply(target) - // kotlin("multiplatform") targeting Java platforms. + // kotlin("multiplatform") target.plugins.withType { target.configure { sourceSets { @@ -64,6 +65,14 @@ class BurstPlugin : KotlinCompilerPluginSupportPlugin { add("testImplementation", "app.cash.burst:burst:$burstVersion") } } + + // kotlin("android") + target.plugins.withType { + target.dependencies { + add("testImplementation", "app.cash.burst:burst:$burstVersion") + add("androidTestImplementation", "app.cash.burst:burst:$burstVersion") + } + } } override fun applyToCompilation( 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 fee5eb6..d679c51 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 @@ -22,6 +22,7 @@ import assertk.assertions.containsExactlyInAnyOrder import assertk.assertions.isEmpty import assertk.assertions.isEqualTo import assertk.assertions.isFalse +import assertk.assertions.isIn import assertk.assertions.isTrue import java.io.File import org.gradle.testkit.runner.GradleRunner @@ -65,8 +66,7 @@ class BurstGradlePluginTest { val taskName = ":lib:$testTaskName" val result = createRunner(projectDir, "clean", taskName).build() - assertThat(SUCCESS_OUTCOMES) - .contains(result.task(taskName)!!.outcome) + assertThat(result.task(taskName)!!.outcome).isIn(*SUCCESS_OUTCOMES) val testResults = projectDir.resolve("lib/build/test-results") @@ -134,8 +134,7 @@ class BurstGradlePluginTest { val taskName = ":lib:test" val result = createRunner(projectDir, "clean", taskName).build() - assertThat(SUCCESS_OUTCOMES) - .contains(result.task(taskName)!!.outcome) + assertThat(result.task(taskName)!!.outcome).isIn(*SUCCESS_OUTCOMES) val testResults = projectDir.resolve("lib/build/test-results") val testXmlFile = testResults.resolve("test/TEST-CoffeeTest.xml") @@ -171,8 +170,7 @@ class BurstGradlePluginTest { val taskName = ":lib:test" val result = createRunner(projectDir, "clean", taskName).build() - assertThat(SUCCESS_OUTCOMES) - .contains(result.task(taskName)!!.outcome) + assertThat(result.task(taskName)!!.outcome).isIn(*SUCCESS_OUTCOMES) val testResults = projectDir.resolve("lib/build/test-results") @@ -206,6 +204,17 @@ class BurstGradlePluginTest { ) } + @Test + fun android() { + val projectDir = File("src/test/projects/android") + + val testTaskName = ":lib:test" + val androidTestTaskName = ":lib:assembleAndroidTest" + val result = createRunner(projectDir, "clean", testTaskName, androidTestTaskName).build() + assertThat(result.task(testTaskName)!!.outcome).isIn(*SUCCESS_OUTCOMES) + assertThat(result.task(androidTestTaskName)!!.outcome).isIn(*SUCCESS_OUTCOMES) + } + private fun createRunner( projectDir: File, vararg taskNames: String, @@ -222,7 +231,7 @@ class BurstGradlePluginTest { } companion object { - val SUCCESS_OUTCOMES = listOf(TaskOutcome.SUCCESS, TaskOutcome.UP_TO_DATE) + val SUCCESS_OUTCOMES = arrayOf(TaskOutcome.SUCCESS, TaskOutcome.UP_TO_DATE) val versionProperty = "-PburstVersion=${System.getProperty("burstVersion")}" } } diff --git a/burst-gradle-plugin/src/test/projects/android/build.gradle.kts b/burst-gradle-plugin/src/test/projects/android/build.gradle.kts new file mode 100644 index 0000000..edc520c --- /dev/null +++ b/burst-gradle-plugin/src/test/projects/android/build.gradle.kts @@ -0,0 +1,38 @@ +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile + +buildscript { + repositories { + maven { + url = file("$rootDir/../../../../../build/testMaven").toURI() + } + mavenCentral() + google() + } + dependencies { + classpath("app.cash.burst:burst-gradle-plugin:${project.property("burstVersion")}") + classpath(libs.android.gradlePlugin) + classpath(libs.kotlin.gradlePlugin) + } +} + +allprojects { + repositories { + maven { + url = file("$rootDir/../../../../../build/testMaven").toURI() + } + mavenCentral() + google() + } + + tasks.withType(JavaCompile::class.java).configureEach { + sourceCompatibility = "1.8" + targetCompatibility = "1.8" + } + + tasks.withType(KotlinJvmCompile::class.java).configureEach { + compilerOptions { + jvmTarget.set(JvmTarget.JVM_1_8) + } + } +} diff --git a/burst-gradle-plugin/src/test/projects/android/lib/build.gradle.kts b/burst-gradle-plugin/src/test/projects/android/lib/build.gradle.kts new file mode 100644 index 0000000..30b5f99 --- /dev/null +++ b/burst-gradle-plugin/src/test/projects/android/lib/build.gradle.kts @@ -0,0 +1,19 @@ +plugins { + id("com.android.library") + kotlin("android") + id("app.cash.burst") +} + +android { + namespace = "com.example" + compileSdk = 35 + + defaultConfig { + minSdk = 21 + } +} + +dependencies { + testImplementation(libs.kotlin.test) + androidTestImplementation(libs.kotlin.test) +} diff --git a/burst-gradle-plugin/src/test/projects/android/lib/src/androidTest/kotlin/AndroidCoffeeTest.kt b/burst-gradle-plugin/src/test/projects/android/lib/src/androidTest/kotlin/AndroidCoffeeTest.kt new file mode 100644 index 0000000..6dcd531 --- /dev/null +++ b/burst-gradle-plugin/src/test/projects/android/lib/src/androidTest/kotlin/AndroidCoffeeTest.kt @@ -0,0 +1,22 @@ +import app.cash.burst.Burst +import kotlin.test.BeforeTest +import kotlin.test.Test + +@Burst +class AndroidCoffeeTest( + private val espresso: Espresso, +) { + @BeforeTest + fun setUp() { + println("set up $espresso") + } + + @Test + fun test(dairy: Dairy) { + println("running $espresso $dairy") + } +} + +enum class Espresso { Decaf, Regular, Double } + +enum class Dairy { None, Milk, Oat } diff --git a/burst-gradle-plugin/src/test/projects/android/lib/src/test/kotlin/CoffeeTest.kt b/burst-gradle-plugin/src/test/projects/android/lib/src/test/kotlin/CoffeeTest.kt new file mode 100644 index 0000000..9833508 --- /dev/null +++ b/burst-gradle-plugin/src/test/projects/android/lib/src/test/kotlin/CoffeeTest.kt @@ -0,0 +1,22 @@ +import app.cash.burst.Burst +import kotlin.test.BeforeTest +import kotlin.test.Test + +@Burst +class CoffeeTest( + private val espresso: Espresso, +) { + @BeforeTest + fun setUp() { + println("set up $espresso") + } + + @Test + fun test(dairy: Dairy) { + println("running $espresso $dairy") + } +} + +enum class Espresso { Decaf, Regular, Double } + +enum class Dairy { None, Milk, Oat } diff --git a/burst-gradle-plugin/src/test/projects/android/settings.gradle.kts b/burst-gradle-plugin/src/test/projects/android/settings.gradle.kts new file mode 100644 index 0000000..78eeed4 --- /dev/null +++ b/burst-gradle-plugin/src/test/projects/android/settings.gradle.kts @@ -0,0 +1,9 @@ +dependencyResolutionManagement { + versionCatalogs { + create("libs") { + from(files("../../../../../gradle/libs.versions.toml")) + } + } +} + +include(":lib") diff --git a/burst-gradle-plugin/src/test/projects/classParameters/build.gradle.kts b/burst-gradle-plugin/src/test/projects/classParameters/build.gradle.kts index dae8c15..66fc2bb 100644 --- a/burst-gradle-plugin/src/test/projects/classParameters/build.gradle.kts +++ b/burst-gradle-plugin/src/test/projects/classParameters/build.gradle.kts @@ -1,3 +1,6 @@ +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile + buildscript { repositories { maven { @@ -8,7 +11,7 @@ buildscript { } dependencies { classpath("app.cash.burst:burst-gradle-plugin:${project.property("burstVersion")}") - classpath(libs.kotlin.gradle.plugin) + classpath(libs.kotlin.gradlePlugin) } } @@ -20,4 +23,15 @@ allprojects { mavenCentral() google() } + + tasks.withType(JavaCompile::class.java).configureEach { + sourceCompatibility = "1.8" + targetCompatibility = "1.8" + } + + tasks.withType(KotlinJvmCompile::class.java).configureEach { + compilerOptions { + jvmTarget.set(JvmTarget.JVM_1_8) + } + } } diff --git a/burst-gradle-plugin/src/test/projects/functionParameters/build.gradle.kts b/burst-gradle-plugin/src/test/projects/functionParameters/build.gradle.kts index dae8c15..66fc2bb 100644 --- a/burst-gradle-plugin/src/test/projects/functionParameters/build.gradle.kts +++ b/burst-gradle-plugin/src/test/projects/functionParameters/build.gradle.kts @@ -1,3 +1,6 @@ +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile + buildscript { repositories { maven { @@ -8,7 +11,7 @@ buildscript { } dependencies { classpath("app.cash.burst:burst-gradle-plugin:${project.property("burstVersion")}") - classpath(libs.kotlin.gradle.plugin) + classpath(libs.kotlin.gradlePlugin) } } @@ -20,4 +23,15 @@ allprojects { mavenCentral() google() } + + tasks.withType(JavaCompile::class.java).configureEach { + sourceCompatibility = "1.8" + targetCompatibility = "1.8" + } + + tasks.withType(KotlinJvmCompile::class.java).configureEach { + compilerOptions { + jvmTarget.set(JvmTarget.JVM_1_8) + } + } } diff --git a/burst-gradle-plugin/src/test/projects/multiplatform/build.gradle.kts b/burst-gradle-plugin/src/test/projects/multiplatform/build.gradle.kts index dae8c15..66fc2bb 100644 --- a/burst-gradle-plugin/src/test/projects/multiplatform/build.gradle.kts +++ b/burst-gradle-plugin/src/test/projects/multiplatform/build.gradle.kts @@ -1,3 +1,6 @@ +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile + buildscript { repositories { maven { @@ -8,7 +11,7 @@ buildscript { } dependencies { classpath("app.cash.burst:burst-gradle-plugin:${project.property("burstVersion")}") - classpath(libs.kotlin.gradle.plugin) + classpath(libs.kotlin.gradlePlugin) } } @@ -20,4 +23,15 @@ allprojects { mavenCentral() google() } + + tasks.withType(JavaCompile::class.java).configureEach { + sourceCompatibility = "1.8" + targetCompatibility = "1.8" + } + + tasks.withType(KotlinJvmCompile::class.java).configureEach { + compilerOptions { + jvmTarget.set(JvmTarget.JVM_1_8) + } + } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 3dc039b..b7c665a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -2,6 +2,7 @@ kotlin = "2.0.21" [libraries] +android-gradlePlugin = "com.android.tools.build:gradle:8.7.1" assertk = "com.willowtreeapps.assertk:assertk:0.28.1" auto-service-annotations = { module = "com.google.auto.service:auto-service-annotations", version = "1.1.1" } auto-service-compiler = { module = "dev.zacsweers.autoservice:auto-service-ksp", version = "1.2.0" } @@ -10,7 +11,7 @@ dokka-gradle-plugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", vers google-ksp = "com.google.devtools.ksp:symbol-processing-gradle-plugin:2.0.21-1.0.25" junit = { module = "junit:junit", version = "4.13.2" } kotlin-compile-testing = { module = "dev.zacsweers.kctfork:core", version = "0.5.1" } -kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } +kotlin-gradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test" } mavenPublish-gradle-plugin = { module = "com.vanniktech:gradle-maven-publish-plugin", version = "0.30.0" }