I am trying to get the Mapstruct annotation processor to work in IntelliJ in a Gradle project.
Ideally, I would expect for all configuration to be in the gradle-file and that anyone could just import the project into IntelliJ and get a complete setup without having to set any preferences manually.
But I am okay with compromises on that.
I am using IntelliJ 2018.3 and Gradle 5.0 with Java 11 (i.e. the latest and greatest). The Mapstruct version is 1.2.0.FINAL.
What I have done:
Configured the Mapstruct annotation processor in my
build.gradle
:compile "org.mapstruct:mapstruct-jdk8:${mapstruct_version}" annotationProcessor "org.mapstruct:mapstruct-processor:${mapstruct_version}"
Selected "Delegate IDE build/run actions to Gradle" in the Preferences under "Build, Execution, Deployment -> Build Tools -> Gradle -> Runner"
In the directory build/classes/java/main/com/myapp/mypackage/mapper/
I see a MyMapperImpl.class
and a MyMapperImpl.java
, so code generation seems to work.
Now I would expect that when I select my annotated abstract MyMapper
class and press ctrlH, that the generated MyMapperImpl
appears in the hierarchy view.
If I manually mark build/classes/java/main/
as a "generated sources" directory (which I really don't want to have to do, see above), the class still does not appear in the hierarchy. But the source code is marked with a lot of errors, as no classes from my project are found, apparently.
Needless to say: I can flawlessly run tests that use the mapper, both from IntelliJ and the command line.