简体   繁体   English

Kotlin 在本地机器上正确编译项目,但通过 Jenkins 抛出异常

[英]Kotlin compiles the project properly on local machine but through Jenkins it throws exception

I have a library which has a companion object value in it like below我有一个库,其中有一个伴随对象值,如下所示

companion object {
    const val QUEUE_CLUSTER_ID = "Commands"
}

and one class of my project depends on this library uses lib's QUEUE_CLUSTER_ID val like below我的项目的一类依赖于这个库使用 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")
    }
}

The problem is kotlin compiles the project properly on my machine however via jenkins I get below error.问题是 kotlin 在我的机器上正确编译了项目,但是通过 jenkins 我得到以下错误。 Error disappears when QUEUE_ID set as normal string.当 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

It seems that the exception was related to kotlin type inference.该异常似乎与 kotlin 类型推断有关。 After I indicate the type specifically compilation has done without an error.在我指明类型之后,编译没有出错。 But why?但为什么? Still don't understand how my machine compiles with type inference?仍然不明白我的机器如何使用类型推断进行编译?

companion object {
    const val QUEUE_CLUSTER_ID: String = "Commands"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM