Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Annotation proccessor configuration from a Gradle multi module build in IntelliJ 2019.3 seems not to work correctly

I have a Gradle multi module project that uses the Mapstruct annotation processor for data type mapping across Java modules. The Gradle build works fine but when I import the project into IntellJ IDEA 2019.3 I get an unexpected annotation processor configuration.

The project structure looks like this

.
├── build.gradle
├── module1
│   └── src
│       └── main
│           └── java
│               └── io
│                   └── wangler
│                       └── mapstruct
│                           ├── ApplicationModule1.java
│                           ├── Person.java
│                           ├── PersonDTO.java
│                           └── PersonMapper.java
├── module2
│   └── src
│       └── main
│           ├── generated
│           │   └── ch
│           │       └── silviowangler
│           │           └── mapstruct
│           │               └── CarMapperImpl.java
│           └── java
│               └── ch
│                   └── silviowangler
│                       └── mapstruct
│                           ├── ApplicationModule2.java
│                           ├── Car.java
│                           ├── CarDTO.java
│                           └── CarMapper.java
└── settings.gradle

and the build.gradle that registers the annotation processor for module1 and module2.

subprojects { p ->

    apply plugin: 'java-library'
    apply plugin: 'groovy'

    repositories {
        jcenter()
    }

    dependencies {

        annotationProcessor 'org.mapstruct:mapstruct-processor:1.3.1.Final'
        implementation 'org.mapstruct:mapstruct:1.3.1.Final'

        testImplementation 'org.codehaus.groovy:groovy-all:2.5.8'

        testImplementation 'org.spockframework:spock-core:1.3-groovy-2.5'
        testImplementation 'junit:junit:4.12'
    }
}

When I compile the project using ./gradlew compileJava all works out fine and I get no compilation errors.

But when I run Rebuild Project withing IntelliJ I get a compilation error in module1 since IntelliJ does not have an annotation processor registered for module1.

Error:(6, 35) java: cannot find symbol
  symbol:   class PersonMapperImpl
  location: class io.wangler.mapstruct.ApplicationModule1

Wrong Annotation processor configuration

Am I doing something wrong here or is this a known IntelliJ issue? The source code for this example can be found at https://github.com/saw303/idea-annotation-processors

like image 469
saw303 Avatar asked Dec 04 '19 11:12

saw303


People also ask

How do I enable annotation processing in IntelliJ?

Press Ctrl+Alt+S to open the IDE settings and select Build, Execution, Deployment | Compiler | Annotation Processors.

How do I enable Mapstruct in IntelliJ?

IntelliJ IDEA If so, open the preferences window, navigate to Compiler -> Annotation processor and untick checkbox “Enable annotation processing” at “Annotation profile for mapstruct-integrationtest”. You should now be able to rebuild MapStruct.


1 Answers

I faced the same issue in IDEA 2019.3. Looks like a bug. It occurs only if two modules has the same set of annotation processors.

To solve the problem you need to add any library using annotationProcessor directive to one of modules. It does not have to be a real annotation processor. This one is working for me:

annotationProcessor "commons-io:commons-io:${commonsIoVersion}"

I have created a defect in JerBrains bugtracker: IDEA-230337

like image 99
Konstantin Kharitonov Avatar answered Sep 19 '22 00:09

Konstantin Kharitonov