我将 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/