fluid-compiler

Compiles code and runs Kapt annotation processing directly, enabling unit testing of annotation processors. Supports custom compiler arguments, Kapt options, and additional configuration settings.

JVM
GitHub stars12
Authorsfluidsonic
Dependents0
LicenseApache License 2.0
Creation dateover 7 years ago

Last activity5 months ago
Latest release0.15.0 (5 months ago)

fluid-compiler

Maven Central Tests Kotlin #fluid-libraries Slack Channel

Compile Kotlin code and run KAPT annotation processing directly from Kotlin, for example to unit test your annotation processors!

Note: KAPT APIs (processors(), kaptOptions()) are deprecated. Migrate to KSP when possible.

Requirements

  • Kotlin 2.3+
  • JDK 21+

Installation

build.gradle.kts:

dependencies {
	implementation("io.fluidsonic.compiler:fluid-compiler:0.14.0")
}

Example

import io.fluidsonic.compiler.*

val result = KotlinCompiler()
	.includesCurrentClasspath()
	.jvmTarget(KotlinJvmTarget.v21)
	.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

Additional configuration

.destination("output")
	.kotlinHome("/path/to/kotlin/home")
	.moduleName("my-module")

Manually setting compiler arguments

.arguments {
	apiVersion = "1.4"
	languageVersion = "1.6"
	newInference = true
}

For a complete list of all compiler arguments check out K2JVMCompilerArguments .

Manually setting Kapt options

.kaptOptions {
	flags += KaptFlag.CORRECT_ERROR_TYPES
	mode = AptMode.STUBS_AND_APT
}

For a complete list of all Kapt options check out KaptOptions.

License

Apache 2.0

JVM
GitHub stars12
Authorsfluidsonic
Dependents0
LicenseApache License 2.0
Creation dateover 7 years ago

Last activity5 months ago
Latest release0.15.0 (5 months ago)

fluid-compiler

Maven Central Tests Kotlin #fluid-libraries Slack Channel

Compile Kotlin code and run KAPT annotation processing directly from Kotlin, for example to unit test your annotation processors!

Note: KAPT APIs (processors(), kaptOptions()) are deprecated. Migrate to KSP when possible.

Requirements

  • Kotlin 2.3+
  • JDK 21+

Installation

build.gradle.kts:

dependencies {
	implementation("io.fluidsonic.compiler:fluid-compiler:0.14.0")
}

Example

import io.fluidsonic.compiler.*

val result = KotlinCompiler()
	.includesCurrentClasspath()
	.jvmTarget(KotlinJvmTarget.v21)
	.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

Additional configuration

.destination("output")
	.kotlinHome("/path/to/kotlin/home")
	.moduleName("my-module")

Manually setting compiler arguments

.arguments {
	apiVersion = "1.4"
	languageVersion = "1.6"
	newInference = true
}

For a complete list of all compiler arguments check out K2JVMCompilerArguments .

Manually setting Kapt options

.kaptOptions {
	flags += KaptFlag.CORRECT_ERROR_TYPES
	mode = AptMode.STUBS_AND_APT
}

For a complete list of all Kapt options check out KaptOptions.

License

Apache 2.0