mapstruct and gradle configuratoin issue in Intellij IDEA
Asked Answered
P

4

9

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

Prevision answered 14/8, 2016 at 23:34 Comment(1)
did you get it figured out?Creole
D
8

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

Dulcie answered 14/7, 2017 at 17:37 Comment(0)
I
2

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!

Itchy answered 10/4, 2019 at 6:21 Comment(0)
F
1

From Mac OS

  1. Please remove build generated folder.
  2. Click Intellij IDEA => click Preferences... from menu => Select Build, Execution, Deployment => Select Gradle => Select Runner
  3. Tick into Deledate IDE build/run actions to gradle checkbox
  4. From run tests using: select Gradle Test Runner from dropdown list.

    enter image description here

Fixer answered 14/3, 2019 at 3:10 Comment(0)
A
0

Another setting I found helpful was to uncheck "Create separate module per source set" File | Settings | Build, Execution, Deployment | Build Tools | Gradle

Uncheck "Create separate module per source set"

Arsenal answered 20/9, 2018 at 17:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.