java - How to add Map Struct Processor without remove other processor paths? - Stack Overflow

admin2025-05-01  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.

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.

Share Improve this question edited Jan 3 at 9:29 Ali İhsan TAŞDELEN asked Jan 2 at 14:51 Ali İhsan TAŞDELENAli İhsan TAŞDELEN 211 silver badge5 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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/

转载请注明原文地址:http://anycun.com/QandA/1746111739a91831.html