maven 当我使用自定义注解处理器时,当我运行mvn install时,Lombok失败

s5a0g9ez  于 2023-10-17  发布在  Maven
关注(0)|答案(1)|浏览(155)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.15</version>
        <relativePath/>
    </parent>

    <properties>
        <java.version>1.8</java.version>
        <name.prefix>busreg-custom</name.prefix>
        <project.encoding>UTF-8</project.encoding>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven-source-plugin.version>3.3.0</maven-source-plugin.version>
        <maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
        <lombok.version>1.18.28</lombok.version>
        <busreg-exception.version>1.0.0-SNAPSHOT</busreg-exception.version>
        <busreg-code-generation.version>1.0.0-SNAPSHOT</busreg-code-generation.version>
    </properties>
    <groupId>com.cic.busreg</groupId>
    <artifactId>busreg-custom</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <name>${name.prefix}</name>
    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.cic.busreg</groupId>
            <artifactId>busreg-code-generation</artifactId>
            <version>${busreg-code-generation.version}</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>${maven-source-plugin.version}</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-plugin.version}</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <encoding>UTF-8</encoding>
                    <annotationProcessors>
                        <annotationProcessor>
                            com.cic.busreg.generation.annotation.instantiation.DisableInstantiationProcessor
                        </annotationProcessor>
                    </annotationProcessors>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>com.cic.busreg</groupId>
                            <artifactId>busreg-code-generation</artifactId>
                            <version>${busreg-code-generation.version}</version>
                        </path>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>${lombok.version}</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

我的pom.xml
我已经编写了一个自定义注解处理器,并配置了maven编译器插件,如下所示
当我运行mvn install时,Lombok失败可以找到我的get和set方法
Symbol not found
com.cic.busreg.generation.annotation.instantiation.DisableInstantiationProcessor是我的自定义注解处理器完整路径

<path>
<groupId>com.cic.busreg</groupId>
<artifactId>busreg-code-generation</artifactId>
<version>${busreg-code-generation.version}</version>
</path>

是我自定义注解处理器maven包
我添加了META-INF/services/javax.annotation.processing.Processorcom.cic.busreg.generation.annotation.instantiation.DisableInstantiationProcessor
我想用lombok打包我的自定义注解处理器,我应该怎么做

jjjwad0x

jjjwad0x1#

您已经通过<annotationProcessorPaths>正确地设置了maven-compiler-plugin应该在哪些依赖项中查找注解处理器。但是,您已经通过在<annotationProcessors>中只提到这个处理器来指示插件只运行您的注解处理器。
要么将lombok添加到<annotationProcessors>,要么完全删除<annotationProcessors>(它将自动检测注解处理器)。

相关问题