Spring Boot 打包问题:module jdk.compiler does not “opens com.sun.tools.javac.processing“ to unnamed...

问题与处理策略

问题描述
<parent>
    <groupId>org.springframework.bootgroupId>
    <artifactId>spring-boot-starter-parentartifactId>
    <version>3.0.5version>
    <relativePath/>
parent>
<dependency>
    <groupId>org.projectlombokgroupId>
    <artifactId>lombokartifactId>
    <version>1.18.4version>
dependency>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-maven-pluginartifactId>
            <version>2.1.1.RELEASEversion>
            <configuration>
                <fork>truefork>
            configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>repackagegoal>
                    goals>
                execution>
            executions>
        plugin>
        <plugin>
            <groupId>org.apache.maven.pluginsgroupId>
            <artifactId>maven-war-pluginartifactId>
            <version>3.1.0version>
            <configuration>
                <failOnMissingWebXml>falsefailOnMissingWebXml>
                <warName>${project.artifactId}warName>
            configuration>
        plugin>
    plugins>
    <finalName>${project.artifactId}finalName>
build>
  • 在 Java Spring Boot 项目中,使用上述配置,打包报如下错误
Unable to make field private com.sun.tools.javac.processing.JavacProcessingEnvironment$DiscoveredProcessors com.sun.tools.javac.processing.JavacProcessingEnvironment.discoveredProcs accessible: 
module jdk.compiler does not "opens com.sun.tools.javac.processing" to unnamed module @3d8512e9
# 翻译

无法使私有字段 com.sun.tools.javac.processing.JavacProcessingEnvironment$DiscoveredProcessors com.sun.tools.javac.processing.JavacProcessingEnvironment.discoveredProcs 可访问:
模块 jdk.compiler 没有将 com.sun.tools.javac.processing 开放给未命名模块 @3d8512e9
问题描述
  1. Lombok 版本过旧,不支持 JDK 17,导致的反射访问错误

  2. 同时,spring-boot-maven-plugin 版本不匹配,导致插件无法正确处理 JDK 17 的字节码

处理策略
  1. 升级 Lombok 版本以适配 JDK 17
<dependency>
    <groupId>org.projectlombokgroupId>
    <artifactId>lombokartifactId>
    <version>1.18.20version>
dependency>
  1. 升级 spring-boot-maven-plugin 与 Spring Boot 主版本一致
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
<version>3.0.5version>

你可能感兴趣的:(后端,-,问题清单,java,spring,boot,后端,开发语言,spring,java-ee,spring,cloud)