Pixnews Anvil-KSP Code Generators

Code generators designed for use with Anvil-KSP to simplify dependency injection in Android applications.
They make it easier to create Dagger components and modules with the Anvil-KSP compiler plugin.

Primarily shared as practical examples of how to use Anvil-KSP generators.

Below is a list of all implemented helpers:

Installation

Release and snapshot versions of the library are published to a self-hosted public repository, as it's currently used in a single project.

Add the following to your project's settings.gradle:

pluginManagement {
repositories {
maven {
url = uri("https://maven.pixnews.ru")
mavenContent {
includeGroup("ru.pixnews.anvil.ksp.codegen")
}
}
}
}

The following type aliases are used in the examples:

typealias DaggerSet<T> = Set<@JvmSuppressWildcards T>
typealias DaggerMap<K, V> = Map<@JvmSuppressWildcards K, @JvmSuppressWildcards V>

Other generator samples

Some other good reposotories with Anvil generators

Contributing

Any type of contributions are welcome. Please see the contribution guide.

License

These services are licensed under Apache 2.0 License. Authors and contributors are listed in the Authors file.

Copyright 2024-2025 pixnews-anvil.codegen project authors and contributors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

All modules:

Link copied to clipboard

A code generator for use with Anvil-KSP that simplifies adding Android Activities to the DI graph with a single @ContributesActivity annotation.

Link copied to clipboard

The ContributesActivity annotation for use with the activity-generator.

Link copied to clipboard

A code generator for use with Anvil-KSP that simplifies injection of the A/B experiments with a @ContributesExperiment / @ContributesExperimentVariantSerializer annotations.

Link copied to clipboard

Dagger declarations for use with the experiment-generator.

Link copied to clipboard

A code generator for use with Anvil-KSP that simplifies adding application initializers to the DI graph with a single @ContributesInitializer annotation.

Link copied to clipboard

The ContributesInitializer annotation for use with the initializer-generator.

Link copied to clipboard

A code generator for use with Anvil-KSP that simplifies dependency injection into junit4 test classes with a single @ContributesTest annotation.

Link copied to clipboard

Dagger declarations for use with the test-generator.

Link copied to clipboard

A code generator for use with Anvil-KSP that simplifies adding Android ViewModels to the DI graph with a single @ContributesViewModel annotation.

Link copied to clipboard

The ContributesViewModel annotation for use with the viewmodel-generator.

Link copied to clipboard

A code generator for use with Anvil-KSP that simplifies adding Android Workers to the DI graph with a single @ContributesCoroutineWorker annotation.

Link copied to clipboard

The ContributesCoroutineWorker annotation for use with the workmanager-generator.