3
votes

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
To make it work, you need to add the processor as a dependency to the kapt configuration, it's where kapt searches for the processors. You can do it by separating the modules and then dependencies { kapt project(':processor') }.hotkey
Moved to separate modules both processor and app. Now when building: Sources output directory is not specified for processor_main, skipping annotation processingSheppard
@Sheppard did you make it work? I'm still having problems with @AutoServiceuser3605025
nope, I got it only working the way it is in accepted answer (through configuring META-INF). Error Sources output directory is not specified for processor_main, skipping annotation processing still is logged, but code is being generated ignoring it.Sheppard

1 Answers

5
votes

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