I have multi-project setup in which there are following subprojects:
- common
- data
- domain
- utility
The projects are build using gradle and coded in Kotlin
All of the above projects are defined as micronaut libraries.
data
depends upon common
domain
depends upon data
utility
depends domain
The utility project is build to generate a JAR which is then deployed on AWS Lambda java runtime
Below is the build.gradle.kts
file for the utility project
plugins {
id("org.jetbrains.kotlin.jvm") version "1.8.21"
id("org.jetbrains.kotlin.plugin.allopen") version "1.8.21"
id("org.jetbrains.kotlin.kapt") version "1.8.21"
id("com.github.johnrengelman.shadow") version "7.1.2"
id("io.micronaut.library") version "3.7.10"
}
group = "com.example"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
val kotlinVersion = project.properties["kotlinVersion"]
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}")
implementation("jakarta.annotation:jakarta.annotation-api")
implementation("io.micronaut.kotlin:micronaut-kotlin-runtime")
implementation("io.micronaut:micronaut-jackson-databind")
implementation("io.micronaut.crac:micronaut-crac")
// AWS Runtime specific
implementation("io.micronaut.aws:micronaut-function-aws")
implementation(project(":domain"))
runtimeOnly("com.fasterxml.jackson.module:jackson-module-kotlin")
runtimeOnly("ch.qos.logback:logback-classic:1.4.8")
}
java {
sourceCompatibility = JavaVersion.toVersion("17")
}
tasks {
compileKotlin {
compilerOptions {
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17)
}
}
compileTestKotlin {
compilerOptions {
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17)
}
}
}
micronaut {
runtime("lambda_java")
testRuntime("junit5")
processing {
incremental(true)
annotations("com.example.*")
}
}
In the above kotlin version is 1.8.21 and micronaut version is 3.10.0
Inside the domain sub-project, there is a service class which has the following line of code
@Inject
lateinit var objectMapper: ObjectMapper
When the code runs the objectMapper instance is not injected here and the code fails with the error
lateinit property objectMapper has not been initialized: kotlin.UninitializedPropertyAccessException
When the same line of code is written in a class of the utility project as a property of a MicronautRequestHandler
type class. It works without any issue.
What might be the problem here? Why can't I inject objectMapper instance in the domain subproject but it works in the utility project?