diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f2b73c7..b404b70 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,14 +3,14 @@ androidGradle = "7.4.2" androidxActivity = "1.5.0" androidxAppCompat = "1.3.1" androidxCompose = "1.2.0" -androidxComposeCompiler = "1.4.4" +androidxComposeCompiler = "1.4.6" androidxCore = "1.7.0" androidxFragment = "1.5.0" androidxLifecycle = "2.5.0" androidxWork = "2.7.0" -anvil = "2.4.4" +anvil = "2.4.8-1-8" dagger = "2.45" -kotlin = "1.8.10" +kotlin = "1.8.20" kotlinxCoroutines = "1.6.4" mavenPublish = "0.22.0" truth = "1.1.3" @@ -37,6 +37,7 @@ androidxLifecycleViewModel = { module = "androidx.lifecycle:lifecycle-viewmodel- androidxLifecycleViewModelCompose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidxLifecycle" } androidxWorkRuntime = { module = "androidx.work:work-runtime-ktx", version.ref = "androidxWork" } anvilAnnotations = { module = "com.squareup.anvil:annotations", version.ref = "anvil" } +anvilAnnotationsOptional = { module = "com.squareup.anvil:annotations-optional", version.ref = "anvil" } anvilCompiler = { module = "com.squareup.anvil:compiler-api", version.ref = "anvil" } anvilCompilerUtils = { module = "com.squareup.anvil:compiler-utils", version.ref = "anvil" } anvilGradle = { module = "com.squareup.anvil:gradle-plugin", version.ref = "anvil" } diff --git a/sample/src/main/java/com/deliveryhero/whetstone/sample/MainWorker.kt b/sample/src/main/java/com/deliveryhero/whetstone/sample/MainWorker.kt index 29f9d39..f1a0f9a 100644 --- a/sample/src/main/java/com/deliveryhero/whetstone/sample/MainWorker.kt +++ b/sample/src/main/java/com/deliveryhero/whetstone/sample/MainWorker.kt @@ -4,9 +4,9 @@ import android.content.Context import android.util.Log import androidx.work.CoroutineWorker import androidx.work.WorkerParameters -import com.deliveryhero.whetstone.ForScope import com.deliveryhero.whetstone.worker.ContributesWorker import com.deliveryhero.whetstone.worker.WorkerScope +import com.squareup.anvil.annotations.optional.ForScope import javax.inject.Inject @ContributesWorker diff --git a/whetstone-compiler/src/main/java/com/deliveryhero/whetstone/compiler/FqNames.kt b/whetstone-compiler/src/main/java/com/deliveryhero/whetstone/compiler/FqNames.kt index b678488..f201f14 100644 --- a/whetstone-compiler/src/main/java/com/deliveryhero/whetstone/compiler/FqNames.kt +++ b/whetstone-compiler/src/main/java/com/deliveryhero/whetstone/compiler/FqNames.kt @@ -9,6 +9,6 @@ internal object FqNames { @JvmField val CONTRIBUTES_INJECTOR = FqName("com.deliveryhero.whetstone.injector.ContributesInjector") @JvmField val AUTO_INJECTOR = FqName("com.deliveryhero.whetstone.meta.AutoInjectorBinding") @JvmField val AUTO_INSTANCE = FqName("com.deliveryhero.whetstone.meta.AutoInstanceBinding") - @JvmField val SINGLE_IN = FqName("com.deliveryhero.whetstone.SingleIn") + @JvmField val SINGLE_IN = FqName("com.squareup.anvil.annotations.optional.SingleIn") @JvmField val APPLICATION = FqName("android.app.Application") } diff --git a/whetstone-worker/src/main/java/com/deliveryhero/whetstone/worker/WorkerComponent.kt b/whetstone-worker/src/main/java/com/deliveryhero/whetstone/worker/WorkerComponent.kt index 4eb2eaf..2c72b7f 100644 --- a/whetstone-worker/src/main/java/com/deliveryhero/whetstone/worker/WorkerComponent.kt +++ b/whetstone-worker/src/main/java/com/deliveryhero/whetstone/worker/WorkerComponent.kt @@ -4,11 +4,11 @@ import android.content.Context import androidx.work.ListenableWorker import androidx.work.WorkerFactory import androidx.work.WorkerParameters -import com.deliveryhero.whetstone.ForScope -import com.deliveryhero.whetstone.SingleIn import com.deliveryhero.whetstone.app.ApplicationScope import com.squareup.anvil.annotations.ContributesSubcomponent import com.squareup.anvil.annotations.ContributesTo +import com.squareup.anvil.annotations.optional.ForScope +import com.squareup.anvil.annotations.optional.SingleIn import dagger.BindsInstance import javax.inject.Provider diff --git a/whetstone-worker/src/test/java/com/deliveryhero/whetstone/worker/CodegenTest.kt b/whetstone-worker/src/test/java/com/deliveryhero/whetstone/worker/CodegenTest.kt index ade10a0..4d5b71a 100644 --- a/whetstone-worker/src/test/java/com/deliveryhero/whetstone/worker/CodegenTest.kt +++ b/whetstone-worker/src/test/java/com/deliveryhero/whetstone/worker/CodegenTest.kt @@ -17,9 +17,9 @@ internal class CodegenTest { import android.content.Context import androidx.work.Worker import androidx.work.WorkerParameters - import com.deliveryhero.whetstone.ForScope import com.deliveryhero.whetstone.worker.ContributesWorker import com.deliveryhero.whetstone.worker.WorkerScope + import com.squareup.anvil.annotations.optional.ForScope import javax.inject.Inject @ContributesWorker diff --git a/whetstone/api/whetstone.api b/whetstone/api/whetstone.api index 691f2e2..1147d49 100644 --- a/whetstone/api/whetstone.api +++ b/whetstone/api/whetstone.api @@ -93,17 +93,9 @@ public final class anvil/hint/subcomponent/com/deliveryhero/whetstone/viewmodel/ public static final fun getCom_deliveryhero_whetstone_viewmodel_ViewModelComponent_scope ()Lkotlin/reflect/KClass; } -public abstract interface annotation class com/deliveryhero/whetstone/ForScope : java/lang/annotation/Annotation { - public abstract fun value ()Ljava/lang/Class; -} - public abstract interface annotation class com/deliveryhero/whetstone/InternalWhetstoneApi : java/lang/annotation/Annotation { } -public abstract interface annotation class com/deliveryhero/whetstone/SingleIn : java/lang/annotation/Annotation { - public abstract fun value ()Ljava/lang/Class; -} - public final class com/deliveryhero/whetstone/Whetstone { public static final field INSTANCE Lcom/deliveryhero/whetstone/Whetstone; public final fun fromActivity (Landroid/app/Activity;)Ljava/lang/Object; diff --git a/whetstone/build.gradle.kts b/whetstone/build.gradle.kts index dfe5220..9b85ec2 100644 --- a/whetstone/build.gradle.kts +++ b/whetstone/build.gradle.kts @@ -11,6 +11,7 @@ anvil { dependencies { api(libs.dagger) + api(libs.anvilAnnotationsOptional) implementation(libs.androidxLifecycleRuntime) implementation(libs.androidxLifecycleProcess) diff --git a/whetstone/src/main/java/com/deliveryhero/whetstone/ForScope.kt b/whetstone/src/main/java/com/deliveryhero/whetstone/ForScope.kt deleted file mode 100644 index eb3abab..0000000 --- a/whetstone/src/main/java/com/deliveryhero/whetstone/ForScope.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.deliveryhero.whetstone - -import dagger.Binds -import dagger.Provides -import javax.inject.Inject -import javax.inject.Qualifier -import javax.inject.Scope -import kotlin.annotation.AnnotationRetention.RUNTIME -import kotlin.reflect.KClass - -/** - * Qualifies this provided type (via [Provides], [Binds], [Inject], etc) - * for a given [value] scope to distinguish it from instances of the same - * type in other scopes. - * - * Note that the [value] does not actually need to be a [Scope]-annotated - * annotation class. It is _solely_ a key. - */ -@Qualifier -@Retention(RUNTIME) -public annotation class ForScope(val value: KClass<*>) diff --git a/whetstone/src/main/java/com/deliveryhero/whetstone/SingleIn.kt b/whetstone/src/main/java/com/deliveryhero/whetstone/SingleIn.kt deleted file mode 100644 index 8c2d372..0000000 --- a/whetstone/src/main/java/com/deliveryhero/whetstone/SingleIn.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.deliveryhero.whetstone - -import dagger.Binds -import dagger.Provides -import javax.inject.Inject -import javax.inject.Scope -import kotlin.annotation.AnnotationRetention.RUNTIME -import kotlin.reflect.KClass - -/** - * Indicates that this provided type (via [Provides], [Binds], [Inject], etc) - * will only have a single instances within the target [value] scope. - * - * Note that the [value] does not actually need to be a [Scope]-annotated - * annotation class. It is _solely_ a key. - */ -@Scope -@Retention(RUNTIME) -public annotation class SingleIn(val value: KClass<*>) diff --git a/whetstone/src/main/java/com/deliveryhero/whetstone/activity/ActivityComponent.kt b/whetstone/src/main/java/com/deliveryhero/whetstone/activity/ActivityComponent.kt index ff32715..05e688f 100644 --- a/whetstone/src/main/java/com/deliveryhero/whetstone/activity/ActivityComponent.kt +++ b/whetstone/src/main/java/com/deliveryhero/whetstone/activity/ActivityComponent.kt @@ -2,11 +2,11 @@ package com.deliveryhero.whetstone.activity import android.app.Activity import androidx.fragment.app.FragmentFactory -import com.deliveryhero.whetstone.SingleIn import com.deliveryhero.whetstone.app.ApplicationScope import com.deliveryhero.whetstone.injector.MembersInjectorMap import com.squareup.anvil.annotations.ContributesSubcomponent import com.squareup.anvil.annotations.ContributesTo +import com.squareup.anvil.annotations.optional.SingleIn import dagger.BindsInstance /** diff --git a/whetstone/src/main/java/com/deliveryhero/whetstone/app/ApplicationComponent.kt b/whetstone/src/main/java/com/deliveryhero/whetstone/app/ApplicationComponent.kt index 98caf3f..3d23558 100644 --- a/whetstone/src/main/java/com/deliveryhero/whetstone/app/ApplicationComponent.kt +++ b/whetstone/src/main/java/com/deliveryhero/whetstone/app/ApplicationComponent.kt @@ -2,9 +2,9 @@ package com.deliveryhero.whetstone.app import android.app.Application import androidx.lifecycle.ViewModelProvider -import com.deliveryhero.whetstone.SingleIn import com.deliveryhero.whetstone.injector.MembersInjectorMap import com.squareup.anvil.annotations.ContributesTo +import com.squareup.anvil.annotations.optional.SingleIn import dagger.BindsInstance import javax.inject.Singleton diff --git a/whetstone/src/main/java/com/deliveryhero/whetstone/app/ApplicationModule.kt b/whetstone/src/main/java/com/deliveryhero/whetstone/app/ApplicationModule.kt index c0598e9..58b454c 100644 --- a/whetstone/src/main/java/com/deliveryhero/whetstone/app/ApplicationModule.kt +++ b/whetstone/src/main/java/com/deliveryhero/whetstone/app/ApplicationModule.kt @@ -5,9 +5,9 @@ import android.content.Context import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.ProcessLifecycleOwner import androidx.lifecycle.lifecycleScope -import com.deliveryhero.whetstone.ForScope import com.deliveryhero.whetstone.injector.MembersInjectorMap import com.squareup.anvil.annotations.ContributesTo +import com.squareup.anvil.annotations.optional.ForScope import dagger.Binds import dagger.Module import dagger.Provides diff --git a/whetstone/src/main/java/com/deliveryhero/whetstone/fragment/FragmentComponent.kt b/whetstone/src/main/java/com/deliveryhero/whetstone/fragment/FragmentComponent.kt index 15c0211..4ba8299 100644 --- a/whetstone/src/main/java/com/deliveryhero/whetstone/fragment/FragmentComponent.kt +++ b/whetstone/src/main/java/com/deliveryhero/whetstone/fragment/FragmentComponent.kt @@ -1,10 +1,10 @@ package com.deliveryhero.whetstone.fragment import androidx.fragment.app.Fragment -import com.deliveryhero.whetstone.SingleIn import com.deliveryhero.whetstone.activity.ActivityScope import com.squareup.anvil.annotations.ContributesSubcomponent import com.squareup.anvil.annotations.ContributesTo +import com.squareup.anvil.annotations.optional.SingleIn import javax.inject.Provider /** diff --git a/whetstone/src/main/java/com/deliveryhero/whetstone/service/ServiceComponent.kt b/whetstone/src/main/java/com/deliveryhero/whetstone/service/ServiceComponent.kt index cc04159..4bbf10b 100644 --- a/whetstone/src/main/java/com/deliveryhero/whetstone/service/ServiceComponent.kt +++ b/whetstone/src/main/java/com/deliveryhero/whetstone/service/ServiceComponent.kt @@ -1,11 +1,11 @@ package com.deliveryhero.whetstone.service import android.app.Service -import com.deliveryhero.whetstone.SingleIn import com.deliveryhero.whetstone.app.ApplicationScope import com.deliveryhero.whetstone.injector.MembersInjectorMap import com.squareup.anvil.annotations.ContributesSubcomponent import com.squareup.anvil.annotations.ContributesTo +import com.squareup.anvil.annotations.optional.SingleIn import dagger.BindsInstance /** diff --git a/whetstone/src/main/java/com/deliveryhero/whetstone/view/ViewComponent.kt b/whetstone/src/main/java/com/deliveryhero/whetstone/view/ViewComponent.kt index 95657db..4811e34 100644 --- a/whetstone/src/main/java/com/deliveryhero/whetstone/view/ViewComponent.kt +++ b/whetstone/src/main/java/com/deliveryhero/whetstone/view/ViewComponent.kt @@ -1,11 +1,11 @@ package com.deliveryhero.whetstone.view import android.view.View -import com.deliveryhero.whetstone.SingleIn import com.deliveryhero.whetstone.activity.ActivityScope import com.deliveryhero.whetstone.injector.MembersInjectorMap import com.squareup.anvil.annotations.ContributesSubcomponent import com.squareup.anvil.annotations.ContributesTo +import com.squareup.anvil.annotations.optional.SingleIn import dagger.BindsInstance /** diff --git a/whetstone/src/main/java/com/deliveryhero/whetstone/viewmodel/ViewModelComponent.kt b/whetstone/src/main/java/com/deliveryhero/whetstone/viewmodel/ViewModelComponent.kt index de3bce5..4fdc966 100644 --- a/whetstone/src/main/java/com/deliveryhero/whetstone/viewmodel/ViewModelComponent.kt +++ b/whetstone/src/main/java/com/deliveryhero/whetstone/viewmodel/ViewModelComponent.kt @@ -2,10 +2,10 @@ package com.deliveryhero.whetstone.viewmodel import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel -import com.deliveryhero.whetstone.SingleIn import com.deliveryhero.whetstone.app.ApplicationScope import com.squareup.anvil.annotations.ContributesSubcomponent import com.squareup.anvil.annotations.ContributesTo +import com.squareup.anvil.annotations.optional.SingleIn import dagger.BindsInstance import javax.inject.Provider diff --git a/whetstone/src/test/java/com/deliveryhero/whetstone/codegen/TestUtil.kt b/whetstone/src/test/java/com/deliveryhero/whetstone/codegen/TestUtil.kt index d6bcae7..48bcd97 100644 --- a/whetstone/src/test/java/com/deliveryhero/whetstone/codegen/TestUtil.kt +++ b/whetstone/src/test/java/com/deliveryhero/whetstone/codegen/TestUtil.kt @@ -1,16 +1,17 @@ @file:OptIn(ExperimentalCompilerApi::class) + package com.deliveryhero.whetstone.codegen -import com.deliveryhero.whetstone.SingleIn import com.deliveryhero.whetstone.app.ApplicationComponent import com.deliveryhero.whetstone.app.ApplicationScope import com.squareup.anvil.annotations.ContributesTo import com.squareup.anvil.annotations.MergeComponent +import com.squareup.anvil.annotations.optional.SingleIn import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy import com.squareup.kotlinpoet.STAR import com.squareup.kotlinpoet.asClassName import com.squareup.kotlinpoet.asTypeName -import com.tschuchort.compiletesting.KotlinCompilation +import com.tschuchort.compiletesting.JvmCompilationResult import dagger.Binds import dagger.Component import dagger.MembersInjector @@ -24,7 +25,8 @@ import kotlin.reflect.full.* import kotlin.test.assertEquals import kotlin.test.assertTrue -internal fun KotlinCompilation.Result.validateInstanceBinding( +@OptIn(ExperimentalCompilerApi::class) +internal fun JvmCompilationResult.validateInstanceBinding( classUnderTest: String, baseClass: KClass<*>, scope: KClass<*> @@ -43,7 +45,8 @@ internal fun KotlinCompilation.Result.validateInstanceBinding( assertEquals(baseClass, bindsMethod.returnType.classifier) } -internal fun KotlinCompilation.Result.validateInjectorBinding(classUnderTest: String, scope: KClass<*>) { +@OptIn(ExperimentalCompilerApi::class) +internal fun JvmCompilationResult.validateInjectorBinding(classUnderTest: String, scope: KClass<*>) { val clas = classLoader.loadClass(classUnderTest).kotlin val bindingModule = classLoader.loadClass("${classUnderTest}BindingsModule").kotlin val membersInjector = MembersInjector::class.asClassName() @@ -62,12 +65,13 @@ internal fun KotlinCompilation.Result.validateInjectorBinding(classUnderTest: St assertEquals(membersInjector.parameterizedBy(STAR), bindsMethod.returnType.asTypeName()) } -internal fun KotlinCompilation.Result.validateAppComponent() { +@OptIn(ExperimentalCompilerApi::class) +internal fun JvmCompilationResult.validateAppComponent() { val appComponent = classLoader.loadClass("GeneratedApplicationComponent").kotlin assertTrue(appComponent.isAbstract) assertTrue(appComponent.hasAnnotation()) - assertEquals(ApplicationScope::class, appComponent.findAnnotation()?.value) + assertEquals(ApplicationScope::class, appComponent.findAnnotation()?.scope) assertEquals(ApplicationScope::class, appComponent.findAnnotation()?.scope) val appComponentFactoryCn = appComponent.asClassName().nestedClass("Factory")