Kapt 无法与 OpenJDK 16 正常工作

2023-12-26

我有一个使用 Kotlin 1.5.0 和 Kapt 作为映射结构的应用程序。我已将 JDK 更新到 16,但出现以下编译错误:

Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.5.0:kapt (kapt) on project X: Compilation failure
java.lang.IllegalAccessError: class org.jetbrains.kotlin.kapt3.base.KaptContext (in unnamed module @0x248e24b) cannot access class com.sun.tools.javac.util.Context (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.util to unnamed module @0x248e24b
    at org.jetbrains.kotlin.kapt3.base.KaptContext.<init>(KaptContext.kt:29)
    at org.jetbrains.kotlin.kapt3.KaptContextForStubGeneration.<init>(KaptContextForStubGeneration.kt:40)
    at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.contextForStubGeneration(Kapt3Extension.kt:285)
    at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:169)
    at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:100)
    at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$invokeExtensionsOnAnalysisComplete(TopDownAnalyzerFacadeForJVM.kt:111)
    at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:121)
    at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:85)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:514)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:505)
    at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:112)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:505)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:189)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli$default(KotlinToJVMBytecodeCompiler.kt:155)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:169)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:52)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:88)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:44)
    at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:98)
    at org.jetbrains.kotlin.maven.KotlinCompileMojoBase.execCompiler(KotlinCompileMojoBase.java:228)
    at org.jetbrains.kotlin.maven.K2JVMCompileMojo.execCompiler(K2JVMCompileMojo.java:237)
    at org.jetbrains.kotlin.maven.kapt.KaptJVMCompilerMojo.execCompiler(KaptJVMCompilerMojo.java:152)
    at org.jetbrains.kotlin.maven.kapt.KaptJVMCompilerMojo.execCompiler(KaptJVMCompilerMojo.java:44)
    at org.jetbrains.kotlin.maven.KotlinCompileMojoBase.execute(KotlinCompileMojoBase.java:209)
    at org.jetbrains.kotlin.maven.K2JVMCompileMojo.execute(K2JVMCompileMojo.java:222)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:47)

我发现 Kapt 和 JDK 16 存在一个未解决的问题:https://youtrack.jetbrains.com/issue/KT-45545 https://youtrack.jetbrains.com/issue/KT-45545,我正在尝试使用--add-打开作为 kotlin-maven-plugin 中的 args 选项,但似乎它们无法正常工作:

<plugin>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>kapt</id>
                    <goals>
                        <goal>kapt</goal>
                    </goals>
                    <configuration>
                        <sourceDirs>
                            <sourceDir>src/main/kotlin</sourceDir>
                            <sourceDir>src/main/java</sourceDir>
                        </sourceDirs>
                        <annotationProcessorPaths>
                            <annotationProcessorPath>
                                <groupId>org.mapstruct</groupId>
                                <artifactId>mapstruct-processor</artifactId>
                                <version>${mapstruct.version}</version>
                            </annotationProcessorPath>
                        </annotationProcessorPaths>
                    </configuration>
                </execution>
            </executions>
            <configuration>
                <args>
                    <arg>-Xjsr305=strict</arg>
                    <arg>-X--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
                    <arg>-X--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
                    <arg>-X--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
                    <arg>-X--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
                    <arg>-X--add-opens=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
                    <arg>-X--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</arg>
                    <arg>-X--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED</arg>
                    <arg>-X--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
                    <arg>-X--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
                    <arg>-X--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED</arg>
                </args>
                <compilerPlugins>
                    <plugin>spring</plugin>
                </compilerPlugins>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.jetbrains.kotlin</groupId>
                    <artifactId>kotlin-maven-allopen</artifactId>
                    <version>${kotlin.version}</version>
                </dependency>
            </dependencies>
</plugin>

当我使用此 args 选项再次执行 Maven 时,会告诉我以下内容:

[INFO] --- kotlin-maven-plugin:1.5.0:kapt (kapt) @ X ---
[WARNING] Source root doesn't exist: /home/nico/IdeaProjects/X/X/src/main/java
[WARNING] 'tools.jar' was not found, kapt may work unreliably
[INFO] Applied plugin: 'spring'
[WARNING] Flag is not supported by this version of the compiler: -X--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
[WARNING] Flag is not supported by this version of the compiler: -X--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED
[WARNING] Flag is not supported by this version of the compiler: -X--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
[WARNING] Flag is not supported by this version of the compiler: -X--add-opens=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
[WARNING] Flag is not supported by this version of the compiler: -X--add-opens=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
[WARNING] Flag is not supported by this version of the compiler: -X--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
[WARNING] Flag is not supported by this version of the compiler: -X--add-opens=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
[WARNING] Flag is not supported by this version of the compiler: -X--add-opens=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
[WARNING] Flag is not supported by this version of the compiler: -X--add-opens=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
[WARNING] Flag is not supported by this version of the compiler: -X--add-opens=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED
  • 如何将这些选项添加到 kotlin-maven-plugin 中?
  • 还有其他可能使用 JDK 16 和 maven 运行 Kapt 吗?

据 JetBrains 报道comment https://youtrack.jetbrains.com/issue/KT-45545#focus=Comments-27-4773544.0-0:

Add org.gradle.jvmargs=--illegal-access=permit to gradle.properties

可以通过用空格分隔选项来组合选项:

org.gradle.jvmargs=-Xmx1536m --illegal-access=permit
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Kapt 无法与 OpenJDK 16 正常工作 的相关文章

随机推荐

  • 获取对象数组中所有指定元素的总和

    我有一个对象数组 如下所示 width 128 90663423245883 height 160 X 0 Y 140 width 277 0938568683375 height 263 X 128 90663423245883 Y 37
  • 正则表达式查找两个字符串的最长公共前缀

    是否有一个正则表达式可以找到两个字符串的最长公共前缀 如果这不能通过一个正则表达式来解决 那么使用正则表达式 perl ruby python 任何东西 的最优雅的代码或 oneliner 是什么 PS 我可以通过编程轻松地做到这一点 我只
  • 如何更改 ggplotly 中条形图的悬停背景颜色

    我使用 ggplotly 绘制图表 当光标移动到图表顶部时 我使用工具提示函数来表示条形图中的值 Source Data lt data frame key c 1 1 1 2 2 2 3 3 3 Product Name c Table
  • 安装 Xcode 4.2 后无法使用本机扩展构建 json (1.6.3)

    您熟悉这个错误吗 我不知道如何解决这个问题 Installing json 1 6 3 with native extensions Gem Installer ExtensionBuildError ERROR Failed to bui
  • 单页应用程序的 AppEngine app.yaml 配置

    我的 app yaml 文件遇到问题 我在 AppEngine 上有一个带有 python 运行时的单页应用程序 Angular2 应用程序 但深层链接未正确路由 这是我的 app yaml 文件 runtime python27 api
  • 上传前获取视频尺寸,客户端

    我有一个视频上传表单 用户单击 浏览 并选择一个文件 如何在用户选择文件时 在文件上传到服务器之前 获取视频尺寸 显然 它必须是客户端的东西 可能是 javascript jquery 或 flash flex 不过更喜欢 js jquer
  • Android 上的 ZXing PDF417

    有人能读到吗PDF417 http en wikipedia org wiki PDF417条形码与使用ZXing http code google com p zxing Android 操作系统上的库 他们支持这一点 根据他们的页面 它
  • 替换捕获组

    如果我有一个带有捕获组的正则表达式 例如foo f 如果我将其与字符串匹配并想要替换第一个捕获组在所有比赛中 with baz so that foo f blah foo f 转换为 foobaz blah foobaz 使用标准库似乎没
  • 错误:尝试使用 pip 安装 pocketsphinx 时,pocketsphinx 的构建轮失败

    我尝试安装 pocketsphinx 并收到以下错误 jandornhege JanDornhegeUbuntu Hermes Basefunktions pip install pocketsphinx Collecting pocket
  • SwiftUI 以编程方式从可表示返回到视图

    我正在尝试在新的 swift ui 应用程序中设置 qr 阅读器 我可以用这一行加载 UIKit qr 阅读器视图 NavigationLink destination QRCodeScan Text Scan QR 这是我的 UIView
  • Spring MVC 表单输入值始终为 null

    我是 Spring MVC 的新手 但对 Java 的 Web 开发并不陌生 我正在尝试创建一个简单的表单 gt 控制器示例 我有一个表单 一个表单控制器 在下面粘贴的上下文 XML 中配置 和我的模型 一个简单的 bean 无论如何 当我
  • 分析和优化游戏 android

    我正在制作我的第一个 Android 游戏 它将是一个使用 opengl es 的 3D 街机游戏 我已经为此工作了很长一段时间 主要是优化引擎以适应未来的灵活性 无论如何 现在我已经完全完成了游戏功能和所有漂亮的东西 但它在不是我的调试手
  • 8.3 之后无法在 Spotlight 中使用键盘扩展

    自从我将键盘扩展项目更新到 Swift 1 2 并将设备更新到 iOS 8 3 后 我无法再在 Spotlight 搜索中使用我的扩展 如果我按住 地球 键 则我的分机不在列表中 如果进入 Spotlight 时它是活动键盘 则会使用系统键
  • 在 Jersey 2.22.2 中获取客户端 ip

    我正在尝试访问正在调用我的其余服务器的客户端 IP 但我只得到 null 作为响应 网络服务器正在运行 我可以从网络浏览器访问它 我尝试过 Context HttpServletRequest 并且还与 Context ContainerR
  • 为什么每个线程在扭曲内都有自己的指令地址计数器?

    CUDA 中的扭曲始终包含 32 个线程 并且所有这 32 个线程都运行相同的指令 https stackoverflow com questions 41009824 how to understand all threads in a
  • 将单元测试慢慢集成到项目中所需采取的步骤

    我目前正在与另一名带薪实习生一起完成一个即将完成的项目 由于这个项目是从一个合作社传承到另一个合作社 所以一路上采取了糟糕的做法 并将测试留到最后 我决定编写单元测试以在测试时学习新东西 然而 我正在开发一个 3 层 紧密耦合的应用程序 它
  • 使用块时的 iPhone EXC_BAD_ACCESS

    我正在尝试使用块创建一个简单的回调 我有一个 MainViewController 其中 addSubView 另一个 DatePickerViewController view 我创建了一个像这样的块 typedef void DateC
  • Heroku 上出现“PGError: FATAL: termination connection due to Administrator command” 的原因是什么?

    我在 Heroku 上有一个 Rails 应用程序 用户可以登录 我定期收到此异常 用户会话控制器 ActiveRecord 语句无效 PGError FATAL 正在终止 由于管理员的连接 命令 n服务器关闭连接 出乎意料 n t这可能意
  • emacs 可以为我重新缩进一大块 HTML 吗?

    在 emacs 中编辑 HTML 时 有没有一种方法可以自动漂亮地格式化标记块 更改如下 table tr td blah td tr table 到这个 table tr td blah td tr table 你可以做sgml pret
  • Kapt 无法与 OpenJDK 16 正常工作

    我有一个使用 Kotlin 1 5 0 和 Kapt 作为映射结构的应用程序 我已将 JDK 更新到 16 但出现以下编译错误 Failed to execute goal org jetbrains kotlin kotlin maven