【发布时间】:2017-09-04 07:37:26
【问题描述】:
我的 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 搜索处理器的地方。你可以通过分离模块然后dependencies { kapt project(':processor') }来做到这一点。 -
移至处理器和应用程序的单独模块。现在在构建时:
Sources output directory is not specified for processor_main, skipping annotation processing -
@Sheppard 你成功了吗?我仍然遇到
@AutoService的问题 -
不,我只得到了它在接受的答案中的工作方式(通过配置 META-INF)。错误
Sources output directory is not specified for processor_main, skipping annotation processing仍然被记录,但生成的代码忽略它。