We are trying to upgrade from Gradle 4.5 to 5.0. After upgrade, compileJava is failing because Mapstruct is not able to resolve values (getters not available obviously) used in @Mapping annotation. This was working fine in Gradle 4.5 .
The code is like this
@Mapper(componentModel = "spring") public interface CAndACodeGenConverter extends BaseConverter<CGen, AGen> { @Mapping(target = "owner", source = "owner.name") @Mapping(target = "useCA", source = "defaultCA") AGen convertToDto(CGen entity); }
Our build.gradle is like this
mapstructVersion = "1.4.1.Final" lombokVersion = "1.18.12" lombokMapstructBindingVersion = "0.2.0" compileOnly('org.projectlombok:lombok:1.18.12') compile("org.mapstruct:mapstruct:${mapstructVersion}") implementation "org.mapstruct:mapstruct:${mapstructVersion}", "org.projectlombok:lombok:${lombokVersion}" annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}", "org.projectlombok:lombok-mapstruct-binding:${lombokMapstructBindingVersion}"
The error we are getting is
error: No property named "owner.name" exists in source parameter(s). Did you mean "null"?
This was working fine in Gradle 4.5 .
Advertisement
Answer
Try to change dependencies order like below:
compileOnly "org.projectlombok:lombok:$lombokVersion" compileOnly "org.mapstruct:mapstruct:${mapstructVersion}" annotationProcessor "org.projectlombok:lombok-mapstruct-binding:0.2.0" annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}" annotationProcessor "org.projectlombok:lombok:$lombokVersion"
I’ve tested it just now and it works.
P.S. IDK why this order is required, got it from lombok-mapstruct-binding related article long time ago