我有一个图书馆,其中有一个伴随对象值,如下所示
companion object {
const val QUEUE_CLUSTER_ID = "Commands"
}
我的项目的一个类依赖于该库,使用lib的QUEUE_CLUSTER_ID val如下所示
data class CreateCatalogItemCommand(
@JsonProperty("styleVariant") val styleVariant: StyleVariant?) : Commandable() {
companion object {
const val QUEUE_ID = QUEUE_CLUSTER_ID.plus("CreateCatalogItemCommand")
}
}
问题是kotlin在我的机器上正确编译了项目,但是通过jenkins我得到了以下错误。当QUEUE_ID设置为普通字符串时,错误消失。
[INFO] --- kotlin-maven-plugin:1.3.21:compile (compile) @ catalog-
service ---
[INFO] Applied plugin: 'spring'
[ERROR] /var/lib/jenkins/workspace/Catalog-Service/src/main/kotlin/com/mg/catalog/command/CreateCatalogItemCommand.kt: (11, 31) Unresolved reference: QUEUE_CLUSTER_ID
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.864s
[INFO] Finished at: Fri Mar 29 08:40:37 UTC 2019
[INFO] Final Memory: 74M/713M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.jetbrains.kotlin:kotlin-maven-
plugin:1.3.21:compile (compile) on project catalog-service: Compilation
failure
[ERROR] /var/lib/jenkins/workspace/Catalog-Service/src/main/kotlin/com/mg/catalog/command/CreateCatalogItemCommand.kt:
[11,31] Unresolved reference: QUEUE_CLUSTER_ID
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to
execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.3.21:compile
(compile) on project catalog-service: Compilation failure
/var/lib/jenkins/workspace/Catalog-Service/src/main/kotlin/com/mg/catalog/command/CreateCatalogItemCommand.kt:[11,31] Unresolved reference: QUEUE_CLUSTER_ID
答案 0 :(得分:1)
似乎异常与kotlin类型推断有关。在指示类型之后,特别编译已完成,没有错误。但为什么?还是不明白我的机器如何通过类型推断进行编译?
companion object {
const val QUEUE_CLUSTER_ID: String = "Commands"
}