Search code examples
javaspringlombokmapstruct

Mapstruct is not updating its getters and setters in the generated source files


I have an entity with a property I used to write like this private Long ICU;

I'm using mapstruct:

Here is my mapper for said entity:

@Mapper(componentModel = "spring")
public interface ProtectionQueryMapper extends EntityMapper<ProtectionQueryDto, Protection> {

    ProtectionQueryDto toDto(Protection protection);

    Protection toEntity(ProtectionQueryDto protectionQueryDto);

    List<Protection> toEntity(List<ProtectionQueryDto> protectionQueryDtos);

    List<ProtectionQueryDto> toDto(List<Protection> protections);

}
public interface EntityMapper<D, E> {

    E toEntity(D dto);

    D toDto(E entity);

    List<E> toEntity(List<D> dtoList);

    List<D> toDto(List<E> entityList);
}

The problem I have is that I want to change the property from ICU go icu, which I did and it resulted in this error:

nested exception is java.lang.NoSuchMethodError:

Protection.getICU()Ljava/lang/Long;

It would seem that mapstruct generated its getters and setters based on: private Long ICU; generating method like setICU and getICU. But now that I have changed the property from ICU to icu mapstruct is not updating its method to setIcu and getIcu.

I cannot change the mapstruct generated file manually.

Also here is my pom.xml (at least the part regarding mapstruct)

<dependency>
  <groupId>org.mapstruct</groupId>
  <artifactId>mapstruct</artifactId>  
  <version>1.3.0.Final</version>
</dependency>

              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.mapstruct</groupId>
                            <artifactId>mapstruct-processor</artifactId>
                            <version>1.3.0.Final</version>
                        </path>
                    </annotationProcessorPaths>
                    <compilerArgs>
                        <compilerArg>
                            <arg>-Amapstruct.defaultComponentModel=spring</arg>
                        </compilerArg>
                    </compilerArgs>
                </configuration>
            </plugin>

Any idea how to have mapstruct update its generated source file?


Solution

  • For some reason the recompile of the project didn't run the annotation processor. MapStruct is invoked by the Java compiler and the maven-compiler-plugin is responsible for cleaning up the folder with the generated classes.

    Doing mvn clean compile will always work. However, if doing a change and then doing mvn compile doesn't, I would try with the latest version of the maven-compiler-plugin and if that still doesn't work create a bug report for the plugin.