⚠️ This repository is archived. Consider migrating your annotation processing setup to KSP. ⚠️
NAPT
What is it?
An alternative to KAPT that skips stub generation and hence runs up to 50% faster
Usage
JDK 9+ is required to run this particular set of tools
Once applied, you can't reference generated code in Kotlin code anymore, so you'd have to write Java bridge classes in
order to reference Java generated code in Kotlin sources.
For example, assume we have the following Kotlin Dagger 2 Component:
`` Kotlin
@Component
interface Component {
@Component.Factory interface Factory {
fun create(): Component } }
Java class ComponentBridge {then, in order to reference the generated component from Kotlin code we have to write a Javabridgethat would look like this:
static Component.Factory factory() { return DaggerComponent.factory(); } }
Gradle plugins { kotlin("kapt") }That's it, now you can easily reference thisbridgefrom your Kotlin code wherever you'd like toSample
You can see an example of usage in sample
Download
#### Add plugin
- javac plugin is distributed through Maven Central
- Gradle plugin is distributed through Gradle Plugin Portal
Remove your old
and replace it with Gradle
plugins {
id("com.sergei-lapin.napt") version("{latest-version}")
}
then you can replace all of your
Gradle
dependencies {
kapt("some dependency")
}
with Gradle
dependencies {
annotationProcessor("some dependency")
}
That's it. Enjoy the speed-up of your annotation processing by ~50%.#### Conflicting NaptTrigger classes
By default, the Gradle plugin will generate NaptTrigger with a module-named package so the FQ names won't clash, but, just in
case, the prefix of the NaptTrigger package can be specified like this:
Gradle
napt {
naptTriggerPackagePrefix.set("com.slapin.napt")
}
Java package com.slapin.napt.sample; class NaptTrigger { }Assume we're in module namedsample, will result in the followingNaptTrigger.java:
Gradle napt { generateNaptTrigger.set(false) }#### Disabling NaptTrigger generationNaptTrigger.javaGeneration of
can be disabled (e.g., when you already have Java sources in your module) by setting the corresponding property tofalse:
Gradle napt { forkJvmArgs.set(listOf("your_custom_arg")) }#### Supplying custom JVM arguments to Java compilercom.slapin.napt.JvmArgsStrongEncapsulationIn order for napt to work, Java compilation runs in a forked process with arguments defined by
. These arguments can be extended by setting the corresponding property in thenaptextension.
Gradle napt { additionalSourceSetsForTriggerGeneration.set(listOf("test")) } ``#### Generating NaptTrigger within additional source setstestSometimes you might need to trigger annotation processing in additional source sets (e.g.
). In such cases you can use corresponding property fromnaptextension:
--- Tranlated By Open Ai Tx | Last indexed: 2026-01-12 ---