Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mapstruct and gradle configuratoin issue in Intellij IDEA

I have a project using gradle, and have mapstruct as one of dependency. everytime I tried to build project, it failed. I guess it is because Mapstruct will generate impl class that gradle was not able to find. Can anyone help me how to configure this in intellij IDEA?

Thanks

like image 988
user3096841 Avatar asked Aug 14 '16 23:08

user3096841


People also ask

How do I enable MapStruct in IntelliJ?

IntelliJ IDEA xml file located in the root folder. IDEA then will load MapStruct, resolve all dependencies and compile the source. If so, open the preferences window, navigate to Compiler -> Annotation processor and untick checkbox “Enable annotation processing” at “Annotation profile for mapstruct-integrationtest”.

How do I resolve Gradle dependencies in IntelliJ?

Press Alt+Insert to open the Generate context menu. From the context menu, select Add dependency. In the Dependencies tool window, in the search field, start typing the name of your dependency. In the list of results select the one you need and click Add.


2 Answers

This works for me

In intellij IDEA go to

File | Settings | Build, Execution, Deployment | Build Tools | Gradle | Runner

Enable Delegate IDE build/run actions. Ref :- https://www.jetbrains.com/idea/whatsnew/#v2016-3-gradle

In build.gradle

buildscript {
    ...    
}
plugins {
    id 'net.ltgt.apt' version '0.9'
}

apply plugin: 'idea'
apply plugin: "net.ltgt.apt"

dependencies {
    ...
    compile 'org.mapstruct:mapstruct-jdk8:1.1.0.Final'
    apt 'org.mapstruct:mapstruct-processor:1.1.0.Final'
}

After Adding this configuration Run your project you can see your generated files in build/generated folder

like image 137
sumit matta Avatar answered Sep 18 '22 21:09

sumit matta


Hey there everyone I had the same issue and found a clean way of solving this issue. I am using two libraries that require annotation processing (Lombok and MapStruct).

Also my IntelliJ is 2019.1 (update yours in case it's older) and Gradle 5.2.1.

First let's configure IntelliJ:

  1. Disable Annotaion Processing in Settings, since we're going to delegate everything to Gradle:

enter image description here

  1. Delegeate IDE actions to Gradle:

enter image description here

Last step is to configure your dependencies correctly in Gradle.

  1. Dependencies section in Gradle:

enter image description here

Now you can execute the Build and Run from both command line and IDE.

Cheers!

like image 23
de.la.ru Avatar answered Sep 21 '22 21:09

de.la.ru