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

Add kotlin-inject-anvil #2326

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
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: 14 additions & 4 deletions algorithm/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,26 @@ kotlin {
}
val desktopMain by getting {
dependsOn(jvmNonAndroidMain)
configurations["kspDesktop"].dependencies.add(libs.kotlinInject.ksp.get())
configurations["kspDesktop"].dependencies.add(libs.sealedEnum.ksp.get())
configurations["kspDesktop"].dependencies.addAll(
listOf(
libs.kotlinInject.ksp.get(),
libs.kotlinInjectAnvil.ksp.get(),
libs.sealedEnum.ksp.get(),
)
)
dependencies {
implementation(libs.jetbrains.compose.ui)
}
}
val androidMain by getting {
dependsOn(jvmMain)
configurations["kspAndroid"].dependencies.add(libs.kotlinInject.ksp.get())
configurations["kspAndroid"].dependencies.add(libs.sealedEnum.ksp.get())
configurations["kspAndroid"].dependencies.addAll(
listOf(
libs.kotlinInject.ksp.get(),
libs.kotlinInjectAnvil.ksp.get(),
libs.sealedEnum.ksp.get(),
)
)
dependencies {
implementation(libs.androidx.tracing)
implementation(libs.kotlinx.coroutines.android)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ import kotlinx.coroutines.flow.produceIn
import kotlinx.coroutines.isActive
import kotlinx.coroutines.selects.select
import me.tatarka.inject.annotations.Inject
import software.amazon.lastmile.kotlin.inject.anvil.AppScope
import software.amazon.lastmile.kotlin.inject.anvil.ContributesBinding

@Inject
@ContributesBinding(AppScope::class)
class ConfigurableGameOfLifeAlgorithm(
private val preferences: ComposeLifePreferences,
private val naiveGameOfLifeAlgorithm: NaiveGameOfLifeAlgorithm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ import com.alexvanyo.composelife.model.HashLifeCellState
import com.alexvanyo.composelife.model.MacroCell
import com.alexvanyo.composelife.model.expandCentered
import com.alexvanyo.composelife.model.toHashLifeCellState
import com.alexvanyo.composelife.scopes.Singleton
import com.google.common.base.Equivalence
import com.google.common.base.Ticker
import com.google.common.cache.CacheBuilder
import com.google.common.cache.CacheLoader
import com.google.common.cache.LoadingCache
import kotlinx.coroutines.withContext
import me.tatarka.inject.annotations.Inject
import software.amazon.lastmile.kotlin.inject.anvil.AppScope
import software.amazon.lastmile.kotlin.inject.anvil.SingleIn
import java.util.concurrent.TimeUnit

@Singleton
@SingleIn(AppScope::class)
@Inject
class HashLifeAlgorithm(
private val dispatchers: ComposeLifeDispatchers,
Expand Down

This file was deleted.

7 changes: 7 additions & 0 deletions app-compat-sync/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ plugins {
alias(libs.plugins.convention.kotlinMultiplatform)
alias(libs.plugins.convention.androidLibrary)
alias(libs.plugins.convention.androidLibraryJacoco)
alias(libs.plugins.convention.androidLibraryKsp)
alias(libs.plugins.convention.androidLibraryTesting)
alias(libs.plugins.convention.detekt)
alias(libs.plugins.gradleDependenciesSorter)
Expand All @@ -47,6 +48,12 @@ kotlin {
}
}
val androidMain by getting {
configurations["kspAndroid"].dependencies.addAll(
listOf(
libs.kotlinInject.ksp.get(),
libs.kotlinInjectAnvil.ksp.get(),
)
)
dependencies {
implementation(libs.androidx.appcompat)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ import com.alexvanyo.composelife.updatable.Updatable
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.onEach
import me.tatarka.inject.annotations.Inject
import software.amazon.lastmile.kotlin.inject.anvil.AppScope
import software.amazon.lastmile.kotlin.inject.anvil.ContributesBinding
import software.amazon.lastmile.kotlin.inject.anvil.SingleIn

@Inject
@ContributesBinding(AppScope::class, boundType = Updatable::class, multibinding = true)
@SingleIn(AppScope::class)
class AppCompatSync(
private val composeLifePreferences: ComposeLifePreferences,
context: @ApplicationContext Context,
Expand Down

This file was deleted.

15 changes: 12 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ kotlin {
}
}
val androidMain by getting {
configurations["kspAndroid"].dependencies.add(libs.kotlinInject.ksp.get())
configurations["kspAndroid"].dependencies.addAll(listOf(
libs.kotlinInject.ksp.get(),
libs.kotlinInjectAnvil.ksp.get(),
))
configurations["baselineProfile"].dependencies.add(projects.appBaselineProfileGenerator)
dependencies {
implementation(libs.androidx.activityCompose)
Expand Down Expand Up @@ -113,10 +116,16 @@ kotlin {
}
}
val androidUnitTest by getting {
configurations["kspAndroidTest"].dependencies.add(libs.kotlinInject.ksp.get())
configurations["kspAndroidTest"].dependencies.addAll(listOf(
libs.kotlinInject.ksp.get(),
libs.kotlinInjectAnvil.ksp.get(),
))
}
val androidInstrumentedTest by getting {
configurations["kspAndroidAndroidTest"].dependencies.add(libs.kotlinInject.ksp.get())
configurations["kspAndroidAndroidTest"].dependencies.addAll(listOf(
libs.kotlinInject.ksp.get(),
libs.kotlinInjectAnvil.ksp.get(),
))
dependencies {
compileOnly(libs.apiGuardian.api)
compileOnly(libs.google.autoValue.annotations)
Expand Down
4 changes: 4 additions & 0 deletions app/dependencies/releaseRuntimeClasspath.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,7 @@ org.jetbrains.kotlinx:kotlinx-serialization-json-jvm:1.8.0
org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.0
org.jetbrains:annotations:23.0.0
org.jspecify:jspecify:1.0.0
software.amazon.lastmile.kotlin.inject.anvil:runtime-android:0.1.2
software.amazon.lastmile.kotlin.inject.anvil:runtime-optional-android:0.1.2
software.amazon.lastmile.kotlin.inject.anvil:runtime-optional:0.1.2
software.amazon.lastmile.kotlin.inject.anvil:runtime:0.1.2
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import com.alexvanyo.composelife.test.TestInjectApplication

actual fun TestComposeLifeApplicationComponent.Companion.createComponent(): TestComposeLifeApplicationComponent {
val application = ApplicationProvider.getApplicationContext<TestInjectApplication>()
val applicationComponent = TestComposeLifeApplicationComponent.create(application)
val applicationComponent = TestComposeLifeApplicationComponent::class.create(application)
application.applicationComponent = applicationComponent
application.uiComponentFactory = {
TestComposeLifeUiComponent.create(applicationComponent, it.activity)
TestComposeLifeUiComponent::class.create(applicationComponent, it.activity)
}
return applicationComponent
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
override lateinit var applicationComponent: ComposeLifeApplicationComponent

override val uiComponentFactory: (UiComponentArguments) -> ComposeLifeUiComponent =
{ ComposeLifeUiComponent.create(applicationComponent, it.activity) }
{ ComposeLifeUiComponent::class.create(applicationComponent, it.activity) }

Check warning on line 34 in app/src/androidMain/kotlin/com/alexvanyo/composelife/ComposeLifeApplication.kt

View check run for this annotation

Codecov / codecov/patch

app/src/androidMain/kotlin/com/alexvanyo/composelife/ComposeLifeApplication.kt#L34

Added line #L34 was not covered by tests

override fun onCreate() {
super.onCreate()

initStrictModeIfNeeded()

applicationComponent = ComposeLifeApplicationComponent.create(this)
applicationComponent = ComposeLifeApplicationComponent::class.create(this)

Check warning on line 41 in app/src/androidMain/kotlin/com/alexvanyo/composelife/ComposeLifeApplication.kt

View check run for this annotation

Codecov / codecov/patch

app/src/androidMain/kotlin/com/alexvanyo/composelife/ComposeLifeApplication.kt#L41

Added line #L41 was not covered by tests

val processLifecycleOwner = applicationComponent.processLifecycleOwner
val updatables = applicationComponent.updatables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,48 +17,36 @@
package com.alexvanyo.composelife

import android.app.Application
import com.alexvanyo.composelife.algorithm.di.AlgorithmComponent
import com.alexvanyo.composelife.algorithm.di.AlgorithmModule
import com.alexvanyo.composelife.appcompatsync.di.AppCompatSyncComponent
import com.alexvanyo.composelife.clock.di.ClockComponent
import com.alexvanyo.composelife.clock.di.ClockModule
import com.alexvanyo.composelife.data.di.RepositoryComponent
import com.alexvanyo.composelife.data.di.RepositoryModule
import com.alexvanyo.composelife.database.di.DatabaseComponent
import com.alexvanyo.composelife.dispatchers.di.DispatchersComponent
import com.alexvanyo.composelife.database.di.DatabaseModule
import com.alexvanyo.composelife.dispatchers.di.DispatchersModule
import com.alexvanyo.composelife.donotkeepprocess.di.DoNotKeepProcessComponent
import com.alexvanyo.composelife.filesystem.di.FileSystemComponent
import com.alexvanyo.composelife.imageloader.di.ImageLoaderComponent
import com.alexvanyo.composelife.imageloader.di.ImageLoaderModule
import com.alexvanyo.composelife.model.di.CellStateParserModule
import com.alexvanyo.composelife.preferences.di.PreferencesComponent
import com.alexvanyo.composelife.preferences.di.PreferencesModule
import com.alexvanyo.composelife.processlifecycle.di.ProcessLifecycleComponent
import com.alexvanyo.composelife.random.di.RandomComponent
import com.alexvanyo.composelife.processlifecycle.di.ProcessLifecycleModule
import com.alexvanyo.composelife.random.di.RandomModule
import com.alexvanyo.composelife.scopes.ApplicationComponent
import com.alexvanyo.composelife.ui.cells.di.CellsImageLoadingComponent
import com.alexvanyo.composelife.updatable.di.UpdatableModule
import me.tatarka.inject.annotations.Component
import software.amazon.lastmile.kotlin.inject.anvil.AppScope
import software.amazon.lastmile.kotlin.inject.anvil.MergeComponent
import software.amazon.lastmile.kotlin.inject.anvil.SingleIn

@Component
@MergeComponent(AppScope::class)
@SingleIn(AppScope::class)
abstract class ComposeLifeApplicationComponent(
application: Application,
) : ApplicationComponent<ComposeLifeApplicationEntryPoint>(application),
AppCompatSyncComponent,
ProcessLifecycleComponent,
AlgorithmComponent,
DatabaseComponent,
RepositoryComponent,
DispatchersComponent,
ClockComponent,
RandomComponent,
PreferencesComponent,
DoNotKeepProcessComponent,
ImageLoaderComponent,
CellsImageLoadingComponent,
FileSystemComponent,
ProcessLifecycleModule,
AlgorithmModule,
DatabaseModule,
RepositoryModule,
DispatchersModule,
ClockModule,
RandomModule,
PreferencesModule,
ImageLoaderModule,
UpdatableModule,
CellStateParserModule {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,38 @@
package com.alexvanyo.composelife

import android.app.Application
import com.alexvanyo.composelife.algorithm.di.AlgorithmComponent
import com.alexvanyo.composelife.algorithm.di.AlgorithmModule
import com.alexvanyo.composelife.clock.di.ClockComponent
import com.alexvanyo.composelife.clock.di.ClockModule
import com.alexvanyo.composelife.data.di.RepositoryComponent
import com.alexvanyo.composelife.data.di.RepositoryModule
import com.alexvanyo.composelife.database.di.TestDatabaseComponent
import com.alexvanyo.composelife.database.di.DatabaseModule
import com.alexvanyo.composelife.dispatchers.di.DispatchersModule
import com.alexvanyo.composelife.dispatchers.di.TestDispatchersComponent
import com.alexvanyo.composelife.donotkeepprocess.di.DoNotKeepProcessComponent
import com.alexvanyo.composelife.filesystem.di.TestFileSystemComponent
import com.alexvanyo.composelife.imageloader.di.ImageLoaderComponent
import com.alexvanyo.composelife.dispatchers.di.TestDispatcherModule
import com.alexvanyo.composelife.imageloader.di.ImageLoaderModule
import com.alexvanyo.composelife.model.di.CellStateParserModule
import com.alexvanyo.composelife.preferences.di.PreferencesModule
import com.alexvanyo.composelife.preferences.di.TestPreferencesComponent
import com.alexvanyo.composelife.processlifecycle.di.ProcessLifecycleComponent
import com.alexvanyo.composelife.random.di.RandomComponent
import com.alexvanyo.composelife.processlifecycle.di.ProcessLifecycleModule
import com.alexvanyo.composelife.random.di.RandomModule
import com.alexvanyo.composelife.scopes.ApplicationComponent
import com.alexvanyo.composelife.ui.cells.di.CellsImageLoadingComponent
import com.alexvanyo.composelife.updatable.di.UpdatableModule
import me.tatarka.inject.annotations.Component
import software.amazon.lastmile.kotlin.inject.anvil.AppScope
import software.amazon.lastmile.kotlin.inject.anvil.MergeComponent
import software.amazon.lastmile.kotlin.inject.anvil.SingleIn

@Component
@MergeComponent(AppScope::class)
@SingleIn(AppScope::class)
abstract class TestComposeLifeApplicationComponent(
application: Application,
) : ApplicationComponent<TestComposeLifeApplicationEntryPoint>(application),
AlgorithmComponent,
RepositoryComponent,
TestDatabaseComponent,
TestDispatchersComponent,
TestPreferencesComponent,
RandomComponent,
ClockComponent,
ProcessLifecycleComponent,
DoNotKeepProcessComponent,
ImageLoaderComponent,
CellsImageLoadingComponent,
TestFileSystemComponent,
AlgorithmModule,
RepositoryModule,
DatabaseModule,
DispatchersModule,
TestDispatcherModule,
PreferencesModule,
RandomModule,
ClockModule,
ProcessLifecycleModule,
ImageLoaderModule,
UpdatableModule,
CellStateParserModule {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import com.alexvanyo.composelife.test.TestInjectApplication

actual fun TestComposeLifeApplicationComponent.Companion.createComponent(): TestComposeLifeApplicationComponent {
val application = ApplicationProvider.getApplicationContext<TestInjectApplication>()
val applicationComponent = TestComposeLifeApplicationComponent.create(application)
val applicationComponent = TestComposeLifeApplicationComponent::class.create(application)
application.applicationComponent = applicationComponent
application.uiComponentFactory = {
TestComposeLifeUiComponent.create(applicationComponent, it.activity)
TestComposeLifeUiComponent::class.create(applicationComponent, it.activity)
}
return applicationComponent
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@
*/

import com.alexvanyo.composelife.buildlogic.ConventionPlugin
import com.alexvanyo.composelife.buildlogic.configureKsp

class AndroidApplicationKspConventionPlugin : ConventionPlugin({
with(pluginManager) {
apply("com.android.application")
apply("com.google.devtools.ksp")
}

configureKsp()
})
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@
*/

import com.alexvanyo.composelife.buildlogic.ConventionPlugin
import com.alexvanyo.composelife.buildlogic.configureKsp

class AndroidLibraryKspConventionPlugin : ConventionPlugin({
with(pluginManager) {
apply("com.android.library")
apply("com.google.devtools.ksp")
}

configureKsp()
})
Loading
Loading