kotlin
@Table(name = "person")
class Person {
}
kotlin
@AutoService(Processor::class)
@SupportedAnnotationTypes("com.example.Table")
@SupportedSourceVersion(SourceVersion.RELEASE_8)
class TableProcessor : AbstractProcessor() {
override fun process(annotations: MutableSet<out TypeElement>, roundEnv: RoundEnvironment): Boolean {
for (element in roundEnv.getElementsAnnotatedWith(Table::class.java)) {
val tableAnnotation = element.getAnnotation(Table::class.java)
val tableName = tableAnnotation.name
val sqlScript = "CREATE TABLE $tableName ...;"
val file = File("generated/sql/$tableName.sql")
file.parentFile.mkdirs()
file.writeText(sqlScript)
}
return true
}
}
groovy
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.5.21'
id 'net.ltgt.apt' version '0.20'
}
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.5.21'
implementation 'com.google.auto.service:auto-service:1.0-rc7'
}
apt {
arguments {
arg("kapt.kotlin.generated", "$buildDir/generated/kapt")
}
}
groovy
plugins {
id 'java-library'
id 'net.ltgt.apt' version '0.20'
}
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.5.21'
implementation 'com.google.auto.service:auto-service:1.0-rc7'
}
apt {
arguments {
arg("kapt.kotlin.generated", "$buildDir/generated/kapt")
}
}
jar {
}