Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't the compiler find the "MappingProcessor" annotation processor?

I'm using IntelliJ 13.0.2 on OSX 10.9.5, using java 1.8. I get this error when trying to run a unit test inside IntelliJ. When I run compile or test via maven at the command line, it runs fine.

I've gone into File->Other Settings->Default Settings->Compiler->Annotation Processors and unchecked Enable annotation processing. I've also tried it with Enable annotation processing checked, and left the defaults selected.

We're running our tests with

@RunWith(MockitoJUnitRunner.class)

and the Annotation processor it can't find is org.mapstruct.ap.MappingProcessor. I don't know where it's getting that from, it's not in our imports. Maybe a dependency from Mockito?

like image 885
user26270 Avatar asked May 20 '15 19:05

user26270


People also ask

How do I run an annotation processor?

Settings -> Build, Execution, Deployment -> Compiler -> Annotation Processors -> Enable Annotation Processing.

How do I enable annotation processing in Lombok Intellij?

Annotation processing isn't enabled by default, though. We need to go to the Preferences | Build, Execution, Deployment | Compiler | Annotation Processors and make sure of the following: Enable annotation processing box is checked.

Why do we need annotation processor?

Annotations provide information to a program at compile time or at runtime based on which the program can take further action. An annotation processor processes these annotations at compile time or runtime to provide functionality such as code generation, error checking, etc.

How does annotation processing work?

The annotation processing is done in multiple rounds. Each round starts with the compiler searching for the annotations in the source files and choosing the annotation processors suited for these annotations. Each annotation processor, in turn, is called on the corresponding sources.


2 Answers

This is happening because of realm. You can use these dependencies

classpath "io.realm:realm-gradle-plugin:2.0.0-SNAPSHOT

classpath 'com.android.tools.build:gradle:2.0.0-alpha3

classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8

2.0.0 version of snapshots. Good Luck!

like image 89
Aleesha Kanwal Avatar answered Sep 18 '22 18:09

Aleesha Kanwal


In the more general case that I encountered with my own Annotation Processor, here's what was necessary.

In the settings page, choose the "Processor Path" radio button. This has to be the target jar, you should try to locate that MappingProcessor jar.

I believe that this is because when running on the terminal, you would do:
javac -cp <pathToAnnotationProcessor.jar> <path to source.java>

like image 23
JoeKir Avatar answered Sep 21 '22 18:09

JoeKir