maven报 Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile(defalut-compile) on project 项目名称:No such compile 'javac'
这个问题纠结了一天,在另外一个电脑是正常的,但是从服务器下载下来到另外一个电脑的时候却出现了如下图问题
看到javac大家都会想到是编译出现问题,而本地的配置如下图所示:
看着配置都是一致的,会是哪里的问题呢?经网上咨询有个大神说是可能是maven没有配置指定的jdk原因,原因如下:
maven是个项目管理工具,如果我们不告诉它我们的代码要使用什么样的jdk版本编译的话,它就会用maven-compiler-plugin默认的jdk版本来进行处理,这样就容易出现版本不匹配的问题,以至于可能导致编译不通过的问题。为了处理这一种情况的出现,在构建maven项目的时候,我习惯性第一步就是配置maven-compiler-plugin插件。解决办法:
在pom.xml中指定使用的版本 1 <build>
2 <plugins> 3 <plugin> 4 <groupId>org.apache.maven.plugins</groupId> 5 <artifactId>maven-compiler-plugin</artifactId>
<!-- 使用3.5.1也是正确 不知道为啥 如果是3.0就是错误的,但是maven里面也有3.0的版本,可能跟我电脑安装的maven版本有关,本地按照maven版本为3.0.5 -->
6 <version>3.1</version> 7 <configuration> 8 <defaultLibBundleDir>lib</defaultLibBundleDir> 9 指定高版本的源码和编译后的字节码文件 10 <source>1.6</source> 11 <target>1.6</target> 12 <optimize>true</optimize> 13 <debug>true</debug> 14 <showDeprecation>true</showDeprecation> 15 <showWarnings>true</showWarnings> 16 <encoding>UTF-8</encoding> 17 </configuration> 18 </plugin> 19 20 </plugins> 21 </build>
经过指定后,电脑可以正常运行了。
问题2:
1 [WARNING] 2 [WARNING] Some problems were encountered while building the effective model for com.xxx.xxx:xxxx:jar:0.0.1-SNAPSHOT 3 [WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 72, column 12 4 [WARNING] 5 [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build. 6 [WARNING] 7 [WARNING] For this reason, future Maven versions might no longer support building such malformed projects. 8 [WARNING]
对照官网用法:http://maven.apache.org/plugins/maven-compiler-plugin/usage.html
起初配置:
1 <plugins> 2 <plugin> 3 <artifactId>maven-compiler-plugin</artifactId> 4 <configuration> 5 <source>1.6</source> 6 <target>1.6</target> 7 <encoding>UTF-8</encoding> 8 </configuration> 9 </plugin> 10 </plugins>
该问题解决办法是需要置顶maven版本,解决办法:
1 <plugins> 2 <plugin> 3 <artifactId>maven-compiler-plugin</artifactId> 4 <version>3.0</version> 5 <configuration> 6 <source>1.6</source> 7 <target>1.6</target> 8 <encoding>UTF-8</encoding> 9 </configuration> 10 </plugin> 11 </plugins>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架