java - 使用 Kotlin Kapt 失败 : error: scoping construct cannot be annotated with type-use annotation: @org. jetbrains.annotations.NotNull

标签 java gradle kotlin error-handling annotation-processing

我将 Vertx Service Gen 注释处理器与 Kotlin kapt 结合使用。

在注释处理器启动之前,我的 kapt 失败,到处都是以下异常消息:

error: scoping construct cannot be annotated with type-use annotation: @org.jetbrains.annotations.NotNull

示例如下:

e: C:\Users\...\build\tmp\kapt3\stubs\main\com\_masked_\objects\User.java:10: error: scoping construct cannot be annotated with type-use annotation: @org.jetbrains.annotations.NotNull
    public abstract java.lang.String getUserName();

e: C:\Users\...\build\tmp\kapt3\stubs\main\com\_masked_\objects\User.java:13: error: scoping construct cannot be annotated with type-use annotation: @org.jetbrains.annotations.NotNull
    public abstract java.lang.String getUrlKey();
                             ^
e: C:\Users\...\build\tmp\kapt3\stubs\main\com\_masked_\objects\User.java:16: error: scoping construct cannot be annotated with type-use annotation: @org.jetbrains.annotations.NotNull
    public abstract com._.objects.File getAvatar();
                                       ^
...

kapt生成的源代码:

public abstract interface User {
    public static final com._.objects.User.Companion Companion = null;

    @org.jetbrains.annotations.NotNull()
    public abstract java.lang.String getUserName(); // line 10

    @org.jetbrains.annotations.NotNull()
    public abstract java.lang.String getUrlKey(); // line 13

    @org.jetbrains.annotations.NotNull()
    public abstract com._.objects.File getAvatar(); // line 16
...
}

它的 kotlin 源文件如下所示:

interface User {

    val userName: String
    val urlKey: String
    val avatar: File
    val signature: String

}

通过阅读this thread ,我现在有点了解情况了,但是我该如何解决这个问题呢?

最佳答案

这是一个 kapt bug,问题跟踪器 link

kotlin 团队提供的解决方法是添加 实现(“org.jetbrains:annotations:15.0”) 到 gradle bulid 文件。

关于java - 使用 Kotlin Kapt 失败 : error: scoping construct cannot be annotated with type-use annotation: @org. jetbrains.annotations.NotNull,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59485306/

相关文章:

gradle - 在 gradle 脚本中跟踪每个任务的执行时间?

android - 使用协程在进行网络调用时更新 UI

java - 如何创建一个 ASM LdcInsnNode 将当前类静态添加到堆栈中?

java - Angular 6 基本身份验证从客户端返回 401

gradle - 如何在 GitHub 工作流程中重用 gradle 缓存

gradle - 在build.gradle中配置Robolectric

java - 可空类型的可选?

java - 安装Android Carbon图书馆的正确方法是什么?

java - 如何使用 InputStream 和 Spring 发送带附件的电子邮件?

java - 我一次运行多个异步任务,我只想关闭这三个任务中的一个