0

I want to use Map Struct in my project but when I implement it in maven-compiler-plugin other all annotationProcessorPaths removed from project (most important one is Lombok). But after hours and hours of researching I cannot find how to add processor without use

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

Okay I added lombok there but now Hikari CP throw problems and I think if I solve the Hikari's problems other techs will be problem again and I don't want to always patch my project. How can I use processor without use ?

Thank you for reading <3

-- UPDATE --

I tried code like,

<dependencies>
    <dependency>
        <groupId>org.mapstruct</groupId>
        <artifactId>mapstruct</artifactId>
        <version>${org.mapstruct.version}</version>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok-mapstruct-binding</artifactId>
        <version>0.2.0</version>
    </dependency>
    <dependency>
        <groupId>org.mapstruct</groupId>
        <artifactId>mapstruct-processor</artifactId>
        <version>${org.mapstruct.version}</version>
        <scope>runtime</scope>
    </dependency>
</dependencies>


<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <compilerArgs>
            <arg>-proc:full</arg>
            <compilerArg>
                -Amapstruct.defaultComponentModel=spring
            </compilerArg>
        </compilerArgs>
    </configuration>
</plugin>

And it couldn't solve, we try add processors without use . I use Java 23.

1 Answer 1

2

Without adding a annotationProcessorPaths to maven-compiler-path all annotation processors available on project class path will be used.

So you need add them to your project dependencies - can be in provided scope if only contains annotation processor - like mapstruct-processor.

But with newer JDK you must provide list of annotation processors or use a parameter: -proc:full

https://inside.java/2023/10/23/quality-heads-up/

https://inside.java/2024/06/18/quality-heads-up/

Sign up to request clarification or add additional context in comments.

5 Comments

Hello @slawomir-jaranowski . Thank you for your answer. I changed my code but still it couldn't solve that problem. I guess I couldn't implement what you mean. Can you give me code example for clearance if that don't bother you? Thanks again. I will my update trying, on my question.
I'd go for provided scope instead of runtime. With runtime you can't use the processor's classes in your code, but the JAR file will get bundled when using Spring Boot, Quarkus, WAR or EAR plugins. With provided you can use the processor's classes in your code, but the JAR file won't get bundled. For me the smaller build artifacts outweighs the risk of using classes unintentionally.
@RobSpoor you are right - I will update it
@AliİhsanTAŞDELEN - can you provide en example code in some public repositories to try reproduce your problem ... what errors do you see?
@SlawomirJaranowski Real problem is after I add annotationProcessorPaths any compiler plugin, other microservices compilers effected and I guess it overrides old annotationProcessorPaths (for example lombok and Spring Boots own processors (for example, @RequiredArgsConstructor)). Before use annotationProcessorPaths they already in use but after addition they need adding manually and I don't want to override them and add them manually because it is boilerplate. I need use MapStructProcessor without override other processors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.