Generator-jhipster: Compilation error: duplicate class

Created on 17 Aug 2015  路  8Comments  路  Source: jhipster/generator-jhipster

Mapstruct causes compilation error.

Steps to reproduce:
1) Generate entity: "yo jhipster:entity foo" having one String field and select DTO option
2) mvn install

Result:

[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /D:/Development/project_name/target/generated-sources/org/projectname/web/rest/mapper/
FooMapperImpl.java:[14,8]duplicate class: org.projectname.web.rest.mapper.FooMapperImpl

Target folder contains duplicate classes:
generated-source/annotaions/org/projectname/web/rest/mapper/FooMapperImpl.java
generated-source/org/projectname/web/rest/mapper/FooMapperImpl.java

The difference between those classes is that the one in the "annotations" folder does not contain timestamp of generation, so it comes from someone who obviously ignores the "mapstruct.suppressGeneratorTimestamp" parameter configured in pom.xml

Any ideas what could cause sources generation being called twice?

Most helpful comment

@akrima could you clarify your point? Do you mean the doc is wrong and are you proposing a change?

${basedir}\target/ with mixed slash and backslash looks suspicious to me.

All 8 comments

I guess you also have your IDE running, and that it created that other class. Can you confirm this?

-> in that case it would be an IDE configuration to do, and it is not explained in our documentation

Running "mvn clean install" from a console with IntelliJ shut down produces the same error.

I have found out what the problem was. I had an issue described in https://github.com/jhipster/generator-jhipster/issues/1558 and in order to solve it I have added this dependency, as advised as a workaround by one of the posters:

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

Removing the processor from main dependencies resolves the problem of erroneous classes generation, but causes IntelliJ to fail with the "java: Annotation processor 'org.mapstruct.ap.MappingProcessor' not found" error. I had to remove this annotations processor from IntelliJ manually in order to be able to compile.

@afedulov could you help us to improve the documentation on this?

Sure, here it is:

https://docs.google.com/document/d/1UiK5ZUWSJ2bAwM4Cg25QjoERtudYrWWPi7qJF97qNUw/edit?usp=sharing

The whole thing actually turned out to be much more convoluted, than initially expected.

Disabling annotation processing in maven-compiler-plugin seems to fix the duplicate class error, might be a more universal solution. This relies on the maven-processor-plugin, which jhipster includes by default, to perform the annotation processing. Just have to add this to the pom:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <source>${maven.compiler.source}</source>
        <target>${maven.compiler.target}</target>
        <proc>none</proc> <!-- disable annotation processing to avoid duplicating maven-processor-plugin output -->
    </configuration>
</plugin>

This allows including mapstruct as a dependency for IntelliJ:

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

I had the same issue but when i inspect the pom.xml i found that i call the dependency

<dependency>
    <groupId>org.mapstruct</groupId>
    <artifactId>mapstruct-processor</artifactId>
    <version>1.0.0.Final</version>
    <scope>compile</scope>
</dependency>

in the build tag too
So i kepp who in the build tag and i remove the other like this:

<build>
        <plugins>
            <plugin>
                <groupId>org.bsc.maven</groupId>
                <artifactId>maven-processor-plugin</artifactId>
                <version>2.2.4</version>
                <executions>
                    <execution>
                        <id>process</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <configuration>
                            <defaultOutputDirectory>${basedir}\target/generated-sources/struct-mapper</defaultOutputDirectory>
                            <processors>
                                <processor>org.mapstruct.ap.MappingProcessor</processor>
                            </processors>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.mapstruct</groupId>
                        <artifactId>mapstruct-processor</artifactId>
                        <version>1.0.0.Final</version>
                        <scope>compile</scope>
                    </dependency>
                </dependencies>
                <configuration>
                    <defaultOutputDirectory>${basedir}\target/generated-sources</defaultOutputDirectory>
                    <processors>
                        <processor>org.mapstruct.ap.MappingProcessor</processor>
                    </processors>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${basedir}\target/generated-sources/struct-mapper</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

@akrima could you clarify your point? Do you mean the doc is wrong and are you proposing a change?

${basedir}\target/ with mixed slash and backslash looks suspicious to me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SudharakaP picture SudharakaP  路  3Comments

DanielFran picture DanielFran  路  3Comments

trajakovic picture trajakovic  路  4Comments

SudharakaP picture SudharakaP  路  3Comments

ahmedeldeeb25 picture ahmedeldeeb25  路  3Comments