I am using Java 17,Gradle as build tool, the following is my gradle dependency
implementation 'org.mapstruct:mapstruct:1.5.5.Final'
implementation 'org.mapstruct:mapstruct-processor:1.5.5.Final'
I am trying to understand MapStruct , but when gradle build,bootRun is called MapStruct is not generating any implementation
Here is the code:
@Mapper(componentModel = "spring")
public interface SimpleMapper {
@Mapping(source = "name",target="name")
@Mapping(source = "totalCount",target="count")
SimpleDto mapToDto(SimpleRO ro);
}
SimpleDto.java
public class SimpleDto {
private String name;
private String count;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCount() {
return count;
}
public void setCount(String count) {
this.count = count;
}
}
SimpleRO.java
public class SimpleRO {
private String name;
private String totalCount;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTotalCount() {
return totalCount;
}
public void setTotalCount(String totalCount) {
this.totalCount = totalCount;
}
}
According to the MapStruct Installation Documentation you have to include mapstruct as a dependency but also as annotationProcessor
in your build.gradle. Like
dependencies {
...
implementation 'org.mapstruct:mapstruct:1.5.5.Final'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.5.Final'
}
In the file you showed, the second part (mapstruct-processor
) was also given as implementation
instead of annotationProcessor
.