Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate a few more modules to use KSP #3217

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
plugins {
id("godtools.application-conventions")
kotlin("kapt")
alias(libs.plugins.firebase.appdistribution)
alias(libs.plugins.firebase.crashlytics)
alias(libs.plugins.firebase.perf)
alias(libs.plugins.google.services)
alias(libs.plugins.grgit)
alias(libs.plugins.hilt)
alias(libs.plugins.ksp)
}

android {
Expand Down Expand Up @@ -129,12 +129,13 @@ android {
dynamicFeatures += ":feature:bundledcontent"
}

kapt {
javacOptions {
option("-Adagger.fastInit=enabled")
}
ksp {
arg("dagger.fastInit", "enabled")
}

// TODO: remove these bug workarounds once they are no longer needed
exportAgpGeneratedSourcesToKsp()

onesky {
sourceStringFiles = listOf(
"strings_account.xml",
Expand Down Expand Up @@ -225,10 +226,8 @@ dependencies {
debugImplementation(libs.gtoSupport.okhttp3)
debugImplementation(libs.leakcanary)

// TODO: transition to KSP for dagger once referencing BuildConfig is supported
// see: https://github.com/google/dagger/issues/4051
kapt(libs.dagger.compiler)
kapt(libs.hilt.compiler)
ksp(libs.dagger.compiler)
ksp(libs.hilt.compiler)

testImplementation(libs.androidx.arch.core.testing)
testImplementation(libs.androidx.lifecycle.runtime.testing)
Expand All @@ -238,7 +237,6 @@ dependencies {
testImplementation(libs.kotlin.coroutines.test)
testImplementation(libs.turbine)
testImplementation(testFixtures(project(":library:model")))
kaptTest(libs.hilt.compiler)
}

// region Firebase App Distribution
Expand Down
22 changes: 22 additions & 0 deletions build-logic/src/main/kotlin/AndroidConfiguration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import com.android.build.api.dsl.CommonExtension
import com.android.build.api.variant.AndroidComponentsExtension
import com.android.build.gradle.BaseExtension
import com.android.build.gradle.TestedExtension
import com.android.build.gradle.tasks.GenerateBuildConfig
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
Expand All @@ -11,6 +12,7 @@ import org.gradle.kotlin.dsl.findByType
import org.gradle.kotlin.dsl.invoke
import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompileTool

internal const val BUILD_TYPE_DEBUG = "debug"
internal const val BUILD_TYPE_QA = "qa"
Expand Down Expand Up @@ -138,3 +140,23 @@ fun CommonExtension<*, *, *, *, *>.configureQaBuildType(project: Project) {
named("${BUILD_TYPE_QA}Implementation") { extendsFrom(getByName("${BUILD_TYPE_DEBUG}Implementation")) }
}
}

// TODO: Work around AGP generated BuildConfig not being exposed to KSP processors.
// see: https://github.com/google/dagger/issues/4051
fun Project.exportAgpGeneratedSourcesToKsp() {
androidComponents {
onVariants { variant ->
val kspTaskName = "ksp" + variant.name.capitalize() + "Kotlin"
val buildConfigTaskName = "generate" + variant.name.capitalize() + "BuildConfig"

afterEvaluate {
tasks.named(kspTaskName) {
val buildConfigSource = tasks.named(buildConfigTaskName, GenerateBuildConfig::class.java)
.map { it.sourceOutputDir }

(this as AbstractKotlinCompileTool<*>).setSource(buildConfigSource)
}
}
}
}
}
11 changes: 6 additions & 5 deletions library/api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id("godtools.library-conventions")
kotlin("kapt")
alias(libs.plugins.ksp)
}

android {
Expand All @@ -16,6 +16,9 @@ android {
}
}

// TODO: remove these bug workarounds once they are no longer needed
exportAgpGeneratedSourcesToKsp()

dependencies {
api(project(":library:model"))

Expand All @@ -37,10 +40,8 @@ dependencies {
implementation(libs.scarlet.adapters.stream.coroutines)
implementation(libs.scarlet.websockets.okhttp)

// TODO: transition to KSP for dagger once referencing BuildConfig is supported
// see: https://github.com/google/dagger/issues/4051
kapt(libs.dagger.compiler)
kapt(libs.hilt.compiler)
ksp(libs.dagger.compiler)
ksp(libs.hilt.compiler)

testImplementation(libs.json)
testImplementation(libs.jsonUnit.assertj)
Expand Down