Kotlin annotation processor: can't make it work

2k views Asked by At

My gradle build:

buildscript {
    ext.kotlin_version = '1.1.4-3'
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: "kotlin-kapt"

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}


kapt {
    processors = "libs.orm.codeGenerators.ModelProcessor" //PROCESSOR
}


dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"

    compile "com.google.auto.service:auto-service:1.0-rc3"   
}

The processor is not in separate module.

Processor does nothing, in #process it simply throws, to see if it's working.

@AutoService(Processor::class)
@SupportedSourceVersion(SourceVersion.RELEASE_8)
class ModelProcessor : AbstractProcessor() {

    override fun process(annotations: MutableSet<out TypeElement>?, roundEnv: RoundEnvironment): Boolean {
        throw(Throwable("foo"))
        return true
    }

    override fun getSupportedAnnotationTypes() : MutableSet<String> {
        return mutableSetOf<String>("*")
    }

}

But absolutely nothing happens. No error, nothing. How can I make it work?

1

There are 1 answers

0
twocity On BEST ANSWER

In my practices, AutoService just ignore kotlin classes. You have to use a java class instead, or write your own META-INF:

main/resources/META-INF/services/javax.annotation.processing.Processor and contains: your.package.ModelProcessor