Skip to content

Commit

Permalink
add optional annotations artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielittner committed Jul 16, 2023
1 parent 4ebc2d2 commit 78f3824
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 0 deletions.
12 changes: 12 additions & 0 deletions annotations-optional/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
plugins {
alias(libs.plugins.kotlin.jvm)
}
apply from: rootProject.file('publishing.gradle')

kotlin {
explicitApi()
}

dependencies {
api libs.inject
}
3 changes: 3 additions & 0 deletions annotations-optional/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POM_NAME=Anvil Optional Annotations
POM_ARTIFACT_ID=annotations-optional
POM_PACKAGING=jar
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.squareup.anvil.annotations.optional

import kotlin.annotation.AnnotationRetention.RUNTIME
import kotlin.reflect.KClass
import javax.inject.Qualifier

/**
* A class based [qualfier](Qualifier).
*
* This can be used in combination with other Anvil annotations to avoid having
* to manually define qualifier annotations for each component and to maintain
* consistency.
*
* Example:
* ```
* interface Authenticator
*
* @ForScope(AppScope::class)
* @ContributesBinding(AppScope::class)
* class CommonAuthenticator @Inject constructor() : Authenticator
*
* @ForScope(UserScope::class)
* @ContributesBinding(UserScope::class)
* class UserAuthenticator @Inject constructor() : Authenticator
* ```
*/
@Qualifier
@Retention(RUNTIME)
public annotation class ForScope(
/**
* The marker that identifies the component in which the annotated object is
* provided or bound in.
*/
val scope: KClass<*>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.squareup.anvil.annotations.optional

import kotlin.annotation.AnnotationRetention.RUNTIME
import kotlin.reflect.KClass
import javax.inject.Scope

/**
* Identifies a type that the injector only instantiates once for the given
* [scope] marker.
*
* This can be used in combination with other Anvil annotations to avoid having
* to manually define scope annotations for each component and to maintain
* consistency.
*
* Component example:
* ```
* @SingleIn(AppScope::class)
* @MergeComponent(AppScope::class)
* interface AppComponent
* ```
*
* Contribution example:
* ```
* interface Authenticator
*
* @SingleIn(AppScope::class)
* @ContributesBinding(AppScope::class)
* class RealAuthenticator @Inject constructor() : Authenticator
* ```
*
* See Also: [@Scope](Scope)
*/
@Scope
@Retention(RUNTIME)
public annotation class SingleIn(
/**
* The marker that identifies this scope.
*/
val scope: KClass<*>,
)
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencyResolutionManagement {
}

include ':annotations'
include ':annotations-optional'
include ':compiler'
include ':compiler-api'
include ':compiler-utils'
Expand Down

0 comments on commit 78f3824

Please sign in to comment.