Compile Kotlin code and run Kapt annotation processing directly from Kotlin, for example to unit test your annotation processors!
build.gradle.kts
:
dependencies {
implementation("io.fluidsonic.compiler:fluid-compiler:0.13.0")
}
import io.fluidsonic.compiler.*
val result = KotlinCompiler()
.includesCurrentClasspath()
.jvmTarget(KotlinJvmTarget.v1_8)
.processors(MyAnnotationProcessor())
.sources("sources", "more-sources/Example.kt")
.compile()
// result.exitCode contains the exit code of the compiler
// result.messages contains all messages printed during compilation and annotation processing
// result.generatedFiles contains all files generated by annotation processors
.destination("output")
.kotlinHome("/path/to/kotlin/home")
.moduleName("my-module")
.arguments {
apiVersion = "1.4"
languageVersion = "1.6"
newInference = true
}
For a complete list of all compiler arguments check out K2JVMCompilerArguments .
.kaptOptions {
flags += KaptFlag.CORRECT_ERROR_TYPES
mode = AptMode.STUBS_AND_APT
}
For a complete list of all Kapt options check out KaptOptions.
Apache 2.0