Search code examples
javaspring-bootintellij-ideamicroservicesmapstruct

Javax dependency in mapstruct generated file after upgrading to spring boot 3


I was tasked with upgrading one rest service in our hub so that it uses spring boot 3. Among others, I removed all javax imports and substituted them with jakarta imports instead. But when I maven package my app I'm getting a javax import in one of the generated files.

Specifically, the import is in this generated class (if the implementation of this class is important to paint the problem I'll add it):

import cz.cvut.fel.czm.api.dto.NotificationGetDTO;
import cz.cvut.fel.czm.api.dto.NotificationPostDTO;
import cz.cvut.fel.czm.model.notification.Notification;
import java.time.LocalDateTime;
import javax.annotation.processing.Generated;
import org.springframework.stereotype.Component;

@Generated(
    value = "org.mapstruct.ap.MappingProcessor",
    date = "2023-08-30T15:34:27+0200",
    comments = "version: 1.5.5.Final, compiler: javac, environment: Java 17.0.2 (Oracle Corporation)"
)
@Component
public class NotificationMapperImpl implements NotificationMapper {

...
}

And this is the actual mapper:

import cz.cvut.fel.czm.api.dto.NotificationGetDTO;
import cz.cvut.fel.czm.api.dto.NotificationPostDTO;
import cz.cvut.fel.czm.model.notification.Notification;
import org.mapstruct.Mapper;

import java.time.LocalDateTime;

@Mapper(componentModel = "spring", imports = {LocalDateTime.class})
public interface NotificationMapper {
    NotificationGetDTO toDTO(Notification notification);

    Notification toModel(NotificationPostDTO notificationPostDTO);
}

I'm using a custom parent for the service, so I'm not in charge of changing the versions of dependencies. But there could be a bug somewhere in the parent files too.

This is my mapstruct dependency from the pom:

        <dependency>
            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct</artifactId>
        </dependency>

And this is the maven plugin configuration I'm using:

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>${org.projectlombok.lombok.version}</version>
                        </path>
                        <path>
                            <groupId>org.mapstruct</groupId>
                            <artifactId>mapstruct-processor</artifactId>
                            <version>${org.mapstruct.mapstruct.version}</version>
                        </path>
                    </annotationProcessorPaths>
                    <compilerArgs>
                        <compilerArg>-Amapstruct.defaultComponentModel=spring</compilerArg>
                    </compilerArgs>
                </configuration>
            </plugin>

I reviewed it and the version of mapstruct we're using is 1.5.5final.

It appears that when I run the service locally, the endpoints are avaliable and working, when I access them via Insomnia, but when I open it in InteliJIDEA, I'm met with "javax.management.InstanceNotFoundException: orh.springframework.boot:type=Endpoint,name=Mappings,*" message.

I tried hardcoding the version of the mapstruct dependency, but it doesn't seem to be the reason for the problem. I also researched which other dependencies could result in the javax dependency, but I couldn't find the culprit.

In other words, everything works, but I'd hate it if this minor thing caused any problems later in production. I checked with other services that had already been migrated, and I don't think any of those had this thing happening.

Thank you for any suggestions.


Solution

  • So, I discovered it wasn't a code-based problem at all. Still not really sure, why it was happening, but I uninstalled the IDE and installed the new version of IntellijIDEA. Now everything is working just fine. I mean, the generated annotation is no longer using the javax dependency and the error is no longer displayed.

    Thank yall for your help.