Skip to content

Commit 6749ce4

Browse files
committed
update: add super config inheritance to kapt
1 parent 9bdafde commit 6749ce4

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

docs/topics/kapt.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,29 @@ kapt.incremental.apt=false
276276

277277
Note that incremental annotation processing requires [incremental compilation](gradle-compilation-and-caches.md#incremental-compilation)
278278
to be enabled as well.
279+
280+
## Inherit annotation processors from superconfigurations
281+
282+
You can define a common set of annotation processors in a separate Gradle configuration as a
283+
superconfiguration and extend it further in kapt-specific configurations for your subprojects.
284+
285+
As an example, for a subproject using [Dagger](https://dagger.dev/), in your `build.gradle(.kts)` file, use the following configuration:
286+
287+
```kotlin
288+
val commonAnnotationProcessors by configurations.creating
289+
configurations.named("kapt") { extendsFrom(commonAnnotationProcessors) }
290+
291+
dependencies {
292+
implementation("com.google.dagger:dagger:2.48.1")
293+
commonAnnotationProcessors("com.google.dagger:dagger-compiler:2.48.1")
294+
}
295+
```
296+
297+
In this example, the `commonAnnotationProcessors` Gradle configuration is your common superconfiguration for annotation processing
298+
that you want to be used for all your projects. You use the [`extendsFrom()`](https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.Configuration.html#org.gradle.api.artifacts.Configuration:extendsFrom)
299+
method to add `commonAnnotationProcessors` as a superconfiguration. kapt sees that the `commonAnnotationProcessors`
300+
Gradle configuration has a dependency on the Dagger annotation processor. Therefore, kapt includes the Dagger annotation processor
301+
in its configuration for annotation processing.
279302

280303
## Java compiler options
281304

docs/topics/whatsnew20.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ This version brings the following changes:
12151215
* [Bumped minimum AGP supported version](#bumped-minimum-supported-agp-version)
12161216
* [New Gradle property to try latest language version](#new-gradle-property-to-try-latest-language-version)
12171217
* [New JSON output format for build reports](#new-json-output-format-for-build-reports)
1218-
* [kapt configurations inherit annotation processors from super configurations](#kapt-configurations-inherit-annotation-processors-from-super-configurations)
1218+
* [kapt configurations inherit annotation processors from superconfigurations](#kapt-configurations-inherit-annotation-processors-from-superconfigurations)
12191219
* [Kotlin Gradle plugin no longer uses deprecated Gradle conventions](#kotlin-gradle-plugin-no-longer-uses-deprecated-gradle-conventions)
12201220

12211221
### New Gradle DSL for compiler options in multiplatform projects
@@ -1636,7 +1636,7 @@ metrics:
16361636
}
16371637
```
16381638

1639-
### kapt configurations inherit annotation processors from super configurations
1639+
### kapt configurations inherit annotation processors from superconfigurations
16401640

16411641
Prior to Kotlin 2.0.0, if you wanted to define a common set of annotation processors in a separate Gradle configuration
16421642
and extend this configuration in kapt-specific configurations for your subprojects, kapt would skip annotation
@@ -1658,7 +1658,7 @@ dependencies {
16581658

16591659
In this example, the `commonAnnotationProcessors` Gradle configuration is your "common" configuration for annotation
16601660
processing that you want to be used for all your projects. You use the [`extendsFrom()`](https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.Configuration.html#org.gradle.api.artifacts.Configuration:extendsFrom)
1661-
method to add "commonAnnotationProcessors" as a super configuration. kapt sees that the `commonAnnotationProcessors`
1661+
method to add "commonAnnotationProcessors" as a superconfiguration. kapt sees that the `commonAnnotationProcessors`
16621662
Gradle configuration has a dependency on the Dagger annotation processor and successfully includes it in its
16631663
configuration for annotation processing.
16641664

0 commit comments

Comments
 (0)