1

I am trying to compile project which uses both Mapstruct and Immutables. The only solution which solves my problem is to run:

  1. mvn clean compile -> fails with compilation failure; cannot find generated classes from Immutables
  2. mvn compile -> succeeds

Which is not acceptable for me.

I've tried recommended solution which you can see in the code section. I've also looked at:

...

<mapstruct.version>1.3.0.Beta2</mapstruct.version>
<immutables.version>2.7.3</immutables.version>

...

<dependency>
    <groupId>org.mapstruct</groupId>
    <artifactId>mapstruct-jdk8</artifactId>
    <version>${mapstruct.version}</version>
</dependency>
<dependency>
    <groupId>org.mapstruct</groupId>
    <artifactId>mapstruct-processor</artifactId>
    <version>${mapstruct.version}</version>
</dependency>

...

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <annotationProcessorPaths>
                    <path>
                        <groupId>org.mapstruct</groupId>
                        <artifactId>mapstruct-processor</artifactId>
                        <version>${mapstruct.version}</version>
                    </path>
                    <path>
                        <groupId>org.immutables</groupId>
                        <artifactId>value</artifactId>
                        <version>${immutables.version}</version>
                    </path>
                </annotationProcessorPaths>
            </configuration>
        </plugin>
    </plugins>
</build>

I would like to be able to only run mvn clean compile in order to get project compiled.

bobo
  • 33
  • 1
  • 4
  • 1
    I cannot explain why there is an order issue here (did not see this before).. you could play around with the order of executions: https://stackoverflow.com/questions/8243912/changing-the-order-of-maven-plugin-execution in the maven-compiler-plugin and the proc only option: https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html this way you could proc-only immutable first and then run the compiler with mapstruct + compile – Sjaak Jan 23 '19 at 19:29
  • Are you using Immutables in the mappers? Can you also try to define the order of the processors in `annotationProcessPaths` and see if that helps? In any case as @sjaak said, the order should be irrelevant – Filip Jan 23 '19 at 19:46
  • I created minimal project to show you the issue, however, I was not able to reproduce it in it. ... I'll try to experiment more and return here if I find the more info. Thanks for now to both of you! – bobo Jan 23 '19 at 20:28

1 Answers1

0

After several hours of building a minimal example of the issue I noticed this line which happened to be the cause of the failing build:

@Mapper(imports = {ImmutableFirstType.class, ImmutableSecondType.class})     // this one
public interface FirstSecondTypeMapper {

I thought imports are necessary in order to make Immutables with mapstruct work. Just used @Mapper and everything went fine.

bobo
  • 33
  • 1
  • 4