Mapstruct: Mapper Implementation class are not getting generated on Intelji 2018 IDE with Gradle 4 build scritps

Created on 17 Jul 2018  路  4Comments  路  Source: mapstruct/mapstruct

I have used mapstruct & lombok on my spring boot project. Mapstruct is not generating the sources on Intelji 2018 IDE, But everything works fine from command line(gradlew build). could please help me resolve this issue ?

Environment

  1. IDE -IntelliJ 2018 Community Edition

  2. Mapstruct Plugin

  3. lombok plugin

  4. Gradle verison 4.8.1

Note : I'm not using IDE delegate options

Even mapstruct & lombok example projects are not working with same configuration.

plugins {
    id 'java'
    id 'net.ltgt.apt' version '0.17'
}

repositories {
    mavenCentral()
    mavenLocal()
}

ext {
    mapstructVersion = "1.2.0.Final"
    lombokVersion = "1.18.0"
}

sourceCompatibility = JavaVersion.VERSION_1_8

dependencies {
    compile "org.mapstruct:mapstruct-jdk8:${mapstructVersion}"
    apt "org.mapstruct:mapstruct-processor:${mapstructVersion}"

    compileOnly "org.projectlombok:lombok:${lombokVersion}"
    apt  "org.projectlombok:lombok:${lombokVersion}"

    testCompile 'junit:junit:4.12'
}


Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.mycompany.mapper.Main.main(Main.java:30)
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: Cannot find implementation for com.mycompany.mapper.SourceTargetMapper
    at org.mapstruct.factory.Mappers.getMapper(Mappers.java:79)
    at com.mycompany.mapper.SourceTargetMapper.<clinit>(SourceTargetMapper.java:31)
    ... 1 more
Caused by: java.lang.ClassNotFoundException: Cannot find implementation for com.mycompany.mapper.SourceTargetMapper
    at org.mapstruct.factory.Mappers.getMapper(Mappers.java:93)
    at org.mapstruct.factory.Mappers.getMapper(Mappers.java:76)
    ... 2 more

Most helpful comment

Finally it is working fine 馃憤. we don't need any apt plugins.

Here is updated gradle file

plugins {
    id 'java'
}

repositories {
    mavenCentral()
    mavenLocal()
}
sourceCompatibility = JavaVersion.VERSION_1_8

dependencies {
    compile group: 'org.mapstruct', name: 'mapstruct-jdk8', version: '1.2.0.Final'
    compileOnly 'org.mapstruct:mapstruct-processor:1.2.0.Final'
    annotationProcessor 'org.mapstruct:mapstruct-processor:1.2.0.Final'
    compileOnly ("org.projectlombok:lombok")

    testCompile 'junit:junit:4.12'
}

Please make sure following things are configured properly

  1. Enable Annotations Processors( Preference->Build Execute Deployment ->Compiler->Annotations Processors )

  2. MapStruct plugin

  3. Lombok plugin

All 4 comments

Finally it is working fine 馃憤. we don't need any apt plugins.

Here is updated gradle file

plugins {
    id 'java'
}

repositories {
    mavenCentral()
    mavenLocal()
}
sourceCompatibility = JavaVersion.VERSION_1_8

dependencies {
    compile group: 'org.mapstruct', name: 'mapstruct-jdk8', version: '1.2.0.Final'
    compileOnly 'org.mapstruct:mapstruct-processor:1.2.0.Final'
    annotationProcessor 'org.mapstruct:mapstruct-processor:1.2.0.Final'
    compileOnly ("org.projectlombok:lombok")

    testCompile 'junit:junit:4.12'
}

Please make sure following things are configured properly

  1. Enable Annotations Processors( Preference->Build Execute Deployment ->Compiler->Annotations Processors )

  2. MapStruct plugin

  3. Lombok plugin

although the MapStruct plugin is a very nice plugin.. I don't think it offers functionality beyond helper functions like completion. So I'm wondering whether that one is really required..

Can anyone provide the Maven solution to this issue?

@morthomtech have you have a look at the mapstruct-lombok example in the examples repository?

Was this page helpful?
0 / 5 - 0 ratings