Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

I have a spring boot project that uses the maven to build. I use the mapstruct in one class. But when I execute mvn spring-boot:run, it failed with the message: "Caused by: java.lang.Error: Unresolved compilation problems:". It is very strange as the mvn compile command can succeed. Then I check the compiled mapper class, it only contains an exception statement, like below:

// Source code is decompiled from a .class file using FernFlower decompiler.
package com.test.mapper;

public class TestMapperImpl {
   public TestMapperImpl() {
      throw new Error("Unresolved compilation problems: \n\tThe import com.test.database.sql.persistence.model cannot be resolved\n\tThe import com.test.vo cannot be resolved\n\tTestMapper cannot be resolved to a type\n\tTestVo cannot be resolved to a type\n\tCusPers cannot be resolved to a type\n\tTestVo cannot be resolved to a type\n\tTestVo cannot be resolved to a type\n");
   }

   public TestVo convertCusPersToTestVo(CusPers cusPers) {
      throw new Error("Unresolved compilation problems: \n\tTestVo cannot be resolved to a type\n\tCusPers cannot be resolved to a type\n\tTestVo cannot be resolved to a type\n\tTestVo cannot be resolved to a type\n");
   }
}

Looks like mapstruct genereted a java file only contains the error throw statement?

I am using :
Java : Java(TM) SE Runtime Environment (build 17.0.12+8-LTS-286) from Oracle
Apache Maven 3.9.9 (8e8579a9e76f7d015ee5ec7bfcdc97d260186937)
Spring boot: 3.4.1
MapStruct: tried both 1.6.3 and 1.5.5 final

You must be logged in to vote

Replies: 3 comments · 4 replies

Comment options

Hi @liudongqing

Can you provide a github project with a reproducer? Haven't seen something like this before.

Thanks in advance!

You must be logged in to vote
1 reply
@chunweilim
Comment options

Hi @thunderhook,

Just to add on, I encountered this issue today as well.
I was able to consistently reproduce it using the following steps (steps 2 and 3 are interchangeable):

  1. mvn clean
  2. mvn compile
  3. mvn compiler:compile

After some debugging, I discovered that in my case, the mapper in target/generated-sources/annotations was generated after target/classes. However, once I ran the third step, the expected mapper class appeared in target/classes.

After (shamefully) admitting defeat and resorting to the final trick in the book, I restarted my machine, and the issue no longer occurred.

This leads me to suspect there might be a sequencing issue during the compilation and annotation processing phases. I’ll continue to monitor this and report back if I encounter it again.

I am using:
Apache Maven 3.9.9
Java 17.0.14
lombok 1.18.38
MapStruct 1.5.5.Final

Comment options

I also have this problem,But it appears randomly.In my case,i found the "target/generated-sources" directory have the right mapstrcut mapper interface implement ,but the classes directory xxxMapperImpl.class show compile errors like below:

@Component
public class SentenceVariantMapperImpl {


    public SentenceVariantMapperImpl() {
        throw new Error("Unresolved compilation problems: \n\tThe import com.englishlearning.application.content.dto.SentenceVariantDTO cannot be resolved\n\tSentenceVariantMapper cannot be resolved to a type\n\tSentenceVariantDTO cannot be resolved to a type\n\tThe method toDTO(SentenceVariant) of type SentenceVariantMapperImpl must override or implement a supertype method\n\tSentenceVariantDTO cannot be resolved to a type\n\tSentenceVariantDTO cannot be resolved\n\tSentenceVariantDTO cannot be resolved to a type\n\tSentenceVariantDTO cannot be resolved to a type\n\tThe method toDTOList(List<SentenceVariant>) of type SentenceVariantMapperImpl must override or implement a supertype method\n\tSentenceVariantDTO cannot be resolved to a type\n\tSentenceVariantDTO cannot be resolved to a type\n\tThe method toDTO(SentenceVariant) from the type SentenceVariantMapperImpl refers to the missing type SentenceVariantDTO\n\tThe method toEntityList(List<SentenceVariantDTO>) of type SentenceVariantMapperImpl must override or implement a supertype method\n\tSentenceVariantDTO cannot be resolved to a type\n\tSentenceVariantDTO cannot be resolved to a type\n");
    }

    public SentenceVariantDTO toDTO(SentenceVariant entity) {
        throw new Error("Unresolved compilation problems: \n\tSentenceVariantDTO cannot be resolved to a type\n\tThe method toDTO(SentenceVariant) of type SentenceVariantMapperImpl must override or implement a supertype method\n\tSentenceVariantDTO cannot be resolved to a type\n\tSentenceVariantDTO cannot be resolved\n");
    }

    public SentenceVariant toEntity(SentenceVariantDTO dto) {
        throw new Error("Unresolved compilation problem: \n\tSentenceVariantDTO cannot be resolved to a type\n");
    }

    public List<SentenceVariantDTO> toDTOList(List<SentenceVariant> entityList) {
        throw new Error("Unresolved compilation problems: \n\tSentenceVariantDTO cannot be resolved to a type\n\tThe method toDTOList(List<SentenceVariant>) of type SentenceVariantMapperImpl must override or implement a supertype method\n\tSentenceVariantDTO cannot be resolved to a type\n\tSentenceVariantDTO cannot be resolved to a type\n\tThe method toDTO(SentenceVariant) from the type SentenceVariantMapperImpl refers to the missing type SentenceVariantDTO\n");
    }

    public List<SentenceVariant> toEntityList(List<SentenceVariantDTO> dtoList) {
        throw new Error("Unresolved compilation problems: \n\tThe method toEntityList(List<SentenceVariantDTO>) of type SentenceVariantMapperImpl must override or implement a supertype method\n\tSentenceVariantDTO cannot be resolved to a type\n\tSentenceVariantDTO cannot be resolved to a type\n");
    }
}

jdk version: Oracle OpenJDK 17.0.1
maven versionn: apache-maven-3.9.4
mapstruct version: 1.5.3.Final

You must be logged in to vote
2 replies
@filiphr
Comment options

I assume that this is happening in your IDE. MapStruct does not generate the class files. MapStruct only generates java classes, so if something goes wrong then it is either with the IDE or with your build tool

@RP0-ruins
Comment options

I have same problem by use IDEA2025 And maven-3.9.10. Did you find a solution to this problem later?

Comment options

I just found this problem.
I found that i also open the same project in Visual Studio Code. when 'mvn clean compile' completed. Vscode also do compile too. but it not compile with maven (not sure).
after close vscode the problem gone.

it took me 4-5Hr for find what happend.

You must be logged in to vote
1 reply
@kafumanto
Comment options

Thanks a lot!!

Setting "java.autobuild.enabled": false seems to work-around this problem, while allowing you to keep VS Code open . Not sure about the real root cause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
8 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.