Skip to content

Commit

Permalink
Add support for Kotlin Android plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeWharton committed Oct 18, 2024
1 parent 72befa1 commit 087517e
Show file tree
Hide file tree
Showing 13 changed files with 185 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion burst-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<KotlinMultiplatformPluginWrapper> {
target.configure<KotlinMultiplatformExtension> {
sourceSets {
Expand All @@ -64,6 +65,14 @@ class BurstPlugin : KotlinCompilerPluginSupportPlugin {
add("testImplementation", "app.cash.burst:burst:$burstVersion")
}
}

// kotlin("android")
target.plugins.withType<KotlinAndroidPluginWrapper> {
target.dependencies {
add("testImplementation", "app.cash.burst:burst:$burstVersion")
add("androidTestImplementation", "app.cash.burst:burst:$burstVersion")
}
}
}

override fun applyToCompilation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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,
Expand All @@ -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")}"
}
}
38 changes: 38 additions & 0 deletions burst-gradle-plugin/src/test/projects/android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
19 changes: 19 additions & 0 deletions burst-gradle-plugin/src/test/projects/android/lib/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -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 }
Original file line number Diff line number Diff line change
@@ -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 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../../../../../gradle/libs.versions.toml"))
}
}
}

include(":lib")
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile

buildscript {
repositories {
maven {
Expand All @@ -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)
}
}

Expand All @@ -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)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile

buildscript {
repositories {
maven {
Expand All @@ -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)
}
}

Expand All @@ -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)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile

buildscript {
repositories {
maven {
Expand All @@ -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)
}
}

Expand All @@ -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)
}
}
}
3 changes: 2 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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" }

Expand Down

0 comments on commit 087517e

Please sign in to comment.