lombok未正常生效问题排查-maven编译问题排查

问题报错-maven编译报错

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Tailgate 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ tailgate ---
[INFO] Deleting D:\gitee\Tailgate\target
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ tailgate ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ tailgate ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 31 source files to D:\gitee\Tailgate\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
......
[ERROR] /D:/gitee/Tailgate/src/main/java/cn/twh/wall/ServerStart.java:[23,7] 找不到符号
[ERROR] 符号:   变量 log
[ERROR] 位置: 类 cn.twh.wall.ServerStart
[ERROR] /D:/gitee/Tailgate/src/main/java/cn/twh/wall/ServerStart.java:[26,5] 找不到符号
[ERROR] 符号:   变量 log
[ERROR] 位置: 类 cn.twh.wall.ServerStart
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

原因分析-idea编译未生效(我的不是这个问题)

  • 检查lombok依赖
<dependency>
   <groupId>org.projectlombok</groupId>
   <artifactId>lombok</artifactId>
   <scope>provided</scope>
</dependency>
  • 检查java文件注解
package cn.twh.wall;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@SpringBootApplication
@EnableDiscoveryClient
@EnableSwagger2
@Slf4j
public class ServerStart {

  public static void main(String[] args) {
    try {
      SpringApplication.run(ServerStart.class, args);
      // 可以尝试增加钩子,在jvm停止时执行指定线程方法
      Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        System.out.println("ShutDown hook");
      }));
    } catch (Exception e) {
      log.info("START ERROR");
      return;
    }
    log.info("START OK");
  }
}
  • 检查Idea的lombok开关
    idea-lombok配置截图

maven编译问题原因分析

lombok在idea中正常,打包不正常。从日志上也可以看出来是由于maven-compiler-plugin导致的异常,那么肯定是这里的配置问题。
配置如下:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <proc>none</proc>
        <source>${jdk.version}</source>
        <target>${jdk.version}</target>
        <encoding>utf-8</encoding>
    </configuration>
</plugin>

这块是之前拷贝的,proc这个参数作用不明,查插件资料:
链接:maven-compiler-plugin文档
得知proc作用:

Sets whether annotation processing is performed or not. Only applies to JDK 1.6+ If not set, both compilation and annotation processing are performed at the same time.
Allowed values are:
none - no annotation processing is performed.
only - only annotation processing is done, no compilation.

翻译:

是否执行注释的处理逻辑。仅适用于JDK 1.6以上版本。如果未设置,则同时执行编译和注释处理逻辑。
可选的值为:
none-不执行注释处理。
only-仅完成注释处理,不进行编译。

我们知道lombok是通过注释和修改编译逻辑实现的。
所以如果我们把proc设置为none会导致lombok无法正常使用。【阻断了lombok的实现基础,lombok肯定没办法正常发挥作用的呀!】

解决办法

知道问题原因了,那么解决办法也就很明朗了:
删除 maven-compiler-plugin 中的参数 proc 设置

  • 6
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值