Skip the gradle ksp task and use the IDE plug-in to quickly process the annotations!
First, make sure you can write an idea plugin using gradle, if you can't, follow gradle-intellij-plugin to build an idea plugin:
repositories {
mavenCentral()
}
dependencies {
implementation("io.github.zsqw123:ksp-ide:$version")
}
In the simplest case, we would like you to use it with kotlinpoet and just need
to extend PoetAnnotationProcessor
, and implement the readAnnotated
:
class FakeAnnotationProcessor : PoetAnnotationProcessor() {
// your annotation class full qualified name
override val annotationFqn: String = FAKE_FQN
override fun readAnnotated(annotated: KtDeclaration): FileSpec? {
// read annotated to generate a kotlinpoet FileSpec
}
}
Just override the icon
, and that's it!
class FakeMarker : AnnotationLineMaker(FakeAnnotationProcessor()) {
override fun icon(): Icon = KotlinIcons.SUSPEND_CALL
}
Then register to your plugin.xml
<idea-plugin xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="/META-INF/ksp-ide.xml"/>
<extensions defaultExtensionNs="com.intellij">
<codeInsight.lineMarkerProvider language="kotlin" implementationClass="zsu.ksp.ide.sample.FakeMarker"/>
</extensions>
</idea-plugin>
Add the following to the gradle.properties
file in the root directory of the corresponding module
ksp_generate_dir=build/generated/ksp/main/kotlin
So we're all done, simply and elegantly.