3
我gradle这个编译:科特林注释处理器:不能使它工作
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"
}
的处理器是不是在单独的模块。
处理器什么都不做,在#process
它只是抛出,看它是否工作。
@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>("*")
}
}
但绝对没有任何反应。没有错误,没有。 我该如何使它工作?
要使其工作,你需要将处理器作为依赖添加到'kapt'配置,这是kapt在那里搜索处理器的地方。你可以通过分离模块,然后依赖项{kapt project(':processor')}'来完成。 – hotkey
移动到单独的处理器和应用程序模块。现在在构建时:'没有为processor_main指定Sources输出目录,跳过注释处理' – Sheppard
@Sheppard是否让它工作?我仍然遇到'@ AutoService' – user3605025