maven 编译有时会失败有时会成功 [英] maven compile sometimes fail and sometimes succeed

查看:62
本文介绍了maven 编译有时会失败有时会成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 vs code 并且已经安装了Lombok Annotations Support for VS Code".我使用maven clear然后编译,编译失败.然后当我几秒钟后尝试 maven compile 时,它​​构建成功.我在两次 Maven 编译之间什么都不做.
我查看了错误信息,似乎 Lombok 注释不起作用.
无法执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile)[ERROR] 符号:方法 setName(java.lang.String)

I use vs code and have already installed "Lombok Annotations Support for VS Code". I use maven clear and then compile, and I got Compilation failure. Then when I try maven compile several seconds later, it build success. I do nothing between two maven compilation.
I check the error message, it seems that Lombok annotations don't work.
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) [ERROR] symbol: method setName(java.lang.String)

[ERROR] 符号:方法 setCustomerUrlERROR] 需要:无参数

当它构建成功时,我收到消息

And when it build success, I got message

[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ withjpa ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ withjpa ---
[INFO] Nothing to compile - all classes are up to date
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS   

我的 pom.xml 是

And my pom.xml is

        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version> <!-- or newer version -->
                <configuration>
                    <source>1.8</source> <!-- depending on your project -->
                    <target>1.8</target> <!-- depending on your project -->
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.mapstruct</groupId>
                            <artifactId>mapstruct-processor</artifactId>
                            <version>${org.mapstruct.version}</version>
                        </path>  

我想知道我应该将插件版本更改为旧版本吗?但是当我将其更改为 3.1.0 时,会出现 CoreException.
这是我的回购:https://github.com/lyl156/backend/blob/master/src/main/java/com/example/withjpa/domain/Category.java

I am wondering that I should change the plugin version to old version ? But when I change it to 3.1.0 there is CoreException.
Here is my repo : https://github.com/lyl156/backend/blob/master/src/main/java/com/example/withjpa/domain/Category.java

推荐答案

试试这个:

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.1</version>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                        <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>${lombok.version}</version>
                            </path>
                        </annotationProcessorPaths>
                        <compilerArgs>
                            <compilerArg>
                                -Amapstruct.defaultComponentModel=spring
                            </compilerArg>
                        </compilerArgs>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

另见:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆