spring boot项目编译报错“exporting a package from system module java.base is not allowed with --release”
文章目录
- 1.问题描述
- 1.1 环境
- 2.描述
- 2. 分析
- 2.1 不使用exporting
- 2.2 不使用--release
- 3.解决方案
- 3.1不使用exporting
- 3.2 不使用--release
1.问题描述
1.1 环境
- IDEA 2023.3
- JDK 21
- Spring boot 3.2.4
- maven-compiler-plugin 3.13.0
2.描述
今天在使用spring boot 3.2.4这个版本时,由于需要使用security包下面的类,因此需要导出相应模块。即:
(图片来源网络,侵删)org.apache.maven.plugins maven-compiler-plugin 3.13.0 21 UTF-8 true 21 21 --add-exports java.base/sun.security.x509=ALL-UNNAMED
但是在进行Maven编译时,报了如下的错误
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0:compile (default-compile) on project demo: Compilation failure [ERROR] exporting a package from system module java.base is not allowed with --release [ERROR] [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]
2. 分析
exporting a package from system module java.base is not allowed with --release 报错信息很清楚,exporting module和–release不能同时使用,那么就只有两个选择了:
- 不使用exporting
- 不使用–release
2.1 不使用exporting
这个还没有具体研究,应该有可以替代的依赖。
2.2 不使用–release
最先需要明白的是,我在什么地方使用了–release?
由于使用了spring boot parent的依赖
org.springframework.boot spring-boot-starter-parent 3.2.4
该依赖当中又包含了
17 @ ${java.version} UTF-8 UTF-8maven.compiler.release这个参数便是引入了release的参数。那解决问题也很简单了,把这个参数去掉就好了。
3.解决方案
3.1不使用exporting
挖个坑
3.2 不使用–release
去掉这个参数,也很简单,只需要在pom文件当中覆盖这个参数的值:
21
这样就可以正常编译项目了,不会再报“exporting a package from system module java.base is not allowed with --release”错误了。
免责声明:我们致力于保护作者版权,注重分享,被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理! 图片声明:本站部分配图来自人工智能系统AI生成,觅知网授权图片,PxHere摄影无版权图库和百度,360,搜狗等多加搜索引擎自动关键词搜索配图,如有侵权的图片,请第一时间联系我们,邮箱:ciyunidc@ciyunshuju.com。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!
