I am trying to generate mapstruct implementation class and it is not getting generated. I am using:
- Springboot: 2.7.5
- Kotlin: 1.7.21
- Gradle: 7.5.1
- Intellij 2022.2.3 (Ultimate)
- Java 17
Following are my implementation classes:
build.gradle.kts
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { id("org.springframework.boot") version "2.7.5" id("io.spring.dependency-management") version "1.0.11.RELEASE" val kotlinVersion = "1.7.21" kotlin("jvm") version kotlinVersion kotlin("plugin.spring") version kotlinVersion kotlin("kapt") version kotlinVersion } java.sourceCompatibility = JavaVersion.VERSION_17 java.targetCompatibility = JavaVersion.VERSION_17 buildscript { dependencies { classpath("org.jetbrains.kotlin:kotlin-noarg:1.4.21") classpath("net.ltgt.gradle:gradle-apt-plugin:0.21") } } apply(plugin = "kotlin-jpa") apply(plugin = "net.ltgt.apt-idea") dependencies { val querydslVersion = "5.0.0" implementation("org.springframework.boot:spring-boot-starter-data-mongodb") api("com.querydsl:querydsl-apt:$querydslVersion") kapt("com.querydsl:querydsl-jpa:$querydslVersion") val mapstructVersion = "1.5.3.Final" implementation("org.mapstruct:mapstruct:$mapstructVersion") kapt("org.mapstruct:mapstruct-processor:$mapstructVersion") } kapt { annotationProcessor("org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor") // arguments { // Set Mapstruct Configuration options here // arg("mapstruct.defaultComponentModel", "spring") // } } tasks.withType<KotlinCompile> { kotlinOptions { freeCompilerArgs = listOf("-Xjsr305=strict") jvmTarget = JavaVersion.VERSION_17.toString() } } tasks.withType<Test> { useJUnitPlatform() }
DomainModelMapper.kt
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING, unmappedTargetPolicy = ReportingPolicy.WARN) interface DomainModelMapper { @Mappings( Mapping(source = "firstName", target = "first_name"), Mapping(source = "lastName", target = "last_name"), ) fun accountCreateToAccount(accountCreate:AccountCreateRequest):Account }
Exception
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type 'com.*****.backend.config.DomainModelMapper'
available: expected at least 1 bean which qualifies as autowire candidate. Dependency
annotations: {}
I also enabled Annotation Processing in IntelliJ. Below is the screenshot:
I do not have Lombok in my project. I have tried the official doc, mapstruct spring extension plugin, various SO answers, and blogs.