在TeamCity上使用kotlin编译android项目失败

Cal*_*lin 9 teamcity continuous-integration android travis-ci kotlin

我的构建步骤使用TeamCity中的gradle构建模板但不幸的是我得到:

[16:29:22][:presentation:compileLocalDebugKotlin] Using kotlin incremental compilation
[16:29:48][:presentation:compileLocalDebugKotlin] Compilation with Kotlin compile daemon was not successful
[16:29:48][:presentation:compileLocalDebugKotlin] java.rmi.UnmarshalException: Error unmarshaling return header; nested exception is:
[16:29:48][:presentation:compileLocalDebugKotlin]   java.io.EOFException
[16:29:48][:presentation:compileLocalDebugKotlin]   at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:229)
[16:29:48][:presentation:compileLocalDebugKotlin]   at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:162)
Run Code Online (Sandbox Code Playgroud)

关于为什么我会得到这个的任何想法?

Jam*_*ald 5

默认情况下,Kotlin 编译器在它自己的进程守护进程中执行。在 CI 上运行时将此配置传递给 Gradle 以在同一构建过程中编译 Kotlin:

-Dkotlin.compiler.execution.strategy="in-process"
Run Code Online (Sandbox Code Playgroud)

禁用 Gradle 守护进程也是 CI 环境中的常见做法:

-Dorg.gradle.daemon=false
Run Code Online (Sandbox Code Playgroud)

人们可能会期望 Gradle 守护进程属性也会禁用 Kotlin 编译器运行守护进程,但目前情况并非如此。GradleKotlinCompilerWork.kt只考虑org.gradle.daemon属性之后kotlin.compiler.execution.strategy属性。如果没有定义执行"daemon"策略,运行器默认使用该策略:

val executionStrategy = System.getProperty(KOTLIN_COMPILER_EXECUTION_STRATEGY_PROPERTY) ?: DAEMON_EXECUTION_STRATEGY
if (executionStrategy == DAEMON_EXECUTION_STRATEGY) {
    val daemonExitCode = compileWithDaemon(compilerClassName, compilerArgs, environment)

    if (daemonExitCode != null) {
        return daemonExitCode
    }
    else {
        log.warn("Could not connect to kotlin daemon. Using fallback strategy.")
    }
}

val isGradleDaemonUsed = System.getProperty("org.gradle.daemon")?.let(String::toBoolean)
return if (executionStrategy == IN_PROCESS_EXECUTION_STRATEGY || isGradleDaemonUsed == false) {
    compileInProcess(argsArray, compilerClassName, environment)
}
else {
    compileOutOfProcess(argsArray, compilerClassName, environment)
}
Run Code Online (Sandbox Code Playgroud)

无论 Gradle 守护程序配置如何,"in-process"将执行策略显式设置为都将使您能够compileInProcess()使用,但是,您可能需要在 CI 服务器上禁用这两个守护程序。


Lov*_*vis 4

我遇到了同样的问题。但它与 Kotlin 无关。

我必须禁用 gradle deamon(无论如何都不建议在 CI 服务器上使用)。

-Dorg.gradle.daemon=false在 teamcity 中,您可以通过添加到环境变量来实现GRADLE_OPTS

请参阅https://docs.gradle.org/current/userguide/gradle_daemon.html