项目场景:

创建了一个maven工程,编译时报错


问题描述

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project mybatisplus: Fatal error compiling: 无效的标记: --release -> [Help 1]


原因分析:

项目中maven-plugin版本不匹配。我的IDEA版本2023.2.3,JDK版本为1.8.我是把自己的maven版本降低到3.5.1,编译通过。


解决方案:

在pom.xml中配置编译插件以使用正确的Java版本。添加以下配置到pom.xml中:

			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.5.1</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
				</configuration>
			</plugin>

后续问题

出现警告:[WARNING] Parameter ‘parameters’ is unknown for plugin 'maven-compiler-plugin:3.5.1:compile (default-compile)

解决方案:

将maven-compiler-plugin版本改成3.8.1即可

注意:
我的项目中使用了springboot,版本为2.7.14。Spring官方发布从Spring6以及SprinBoot3.0开始最低支持JDK17,我使用的JDK8,所以选择一个3.0以下的版本即可。
如果修改springboot版本后报错Project ‘org.springframework.boot:spring-boot-starter-parent’ not found,那么有可能是缓存的原因,可以清理一下idea的缓存。

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐