问题报错-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开关
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 设置