Gradle: 无法在Windows上连接到Kotlin守护进程

27
当我尝试执行涉及compileKotlin(或compileTestKotlin)的任务时,我收到此警告并且构建过程需要很长时间:

无法执行增量编译:无法连接到 Kotlin 编译进程

无法连接到 kotlin 守护程序。使用备用策略。


我不确定问题是否与我的操作系统(Windows)有关,但是我将具有同步文件的相同项目放在另一台具有 Linux 操作系统的远程机器上,那里就不存在这个问题。请参见以下比较:

  1. 在我的远程机器上的项目(Linux),其中 Kotlin 源代码有少量更改(在一个模块中):

    $ ./gradlew build
    
    Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
    Use '--warning-mode all' to show the individual deprecation warnings.
    See https://docs.gradle.org/5.0/userguide/command_line_interface.html#sec:command_line_warnings
    
    BUILD SUCCESSFUL in 5s
    46 actionable tasks: 17 executed, 29 up-to-date
    
  2. 同一项目在我本机(Windows)上有相同的更改:

  3. > gradlew build                                                                                       
    
    > Task :backend:compileKotlin                                                                         
    Could not perform incremental compilation: Could not connect to Kotlin compile daemon                 
    Could not connect to kotlin daemon. Using fallback strategy.                                          
    
    warning: the '-d' option with a directory destination is ignored because '-Xbuild-file' is specified  
    
    Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.           
    Use '--warning-mode all' to show the individual deprecation warnings.                                 
    See https://docs.gradle.org/5.0/userguide/command_line_interface.html#sec:command_line_warnings       
    
    BUILD SUCCESSFUL in 14s                                                                               
    46 actionable tasks: 17 executed, 29 up-to-date
    

特别注意上述两个示例中的构建持续时间(以及Windows机器上compileKotlin任务后的警告)。尽管我的本地机器(Windows)具有更强大的硬件,但结果相反(Gradle守护程序在两台机器上都运行)。


为了进一步分析性,我还发布了两台计算机上gradle -vjava -version的输出:

  1. Linux

$ ./gradlew -v

------------------------------------------------------------
Gradle 5.0
------------------------------------------------------------

Build time:   2018-11-26 11:48:43 UTC
Revision:     7fc6e5abf2fc5fe0824aec8a0f5462664dbcd987

Kotlin DSL:   1.0.4
Kotlin:       1.3.10
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          11.0.1 (Oracle Corporation 11.0.1+13)
OS:           Linux 3.10.0-862.11.6.el7.x86_64 amd64


$ java -version
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)
  • Windows:

  • > gradlew -v                                                           
    
    ------------------------------------------------------------           
    Gradle 5.0                                                             
    ------------------------------------------------------------           
    
    Build time:   2018-11-26 11:48:43 UTC                                  
    Revision:     7fc6e5abf2fc5fe0824aec8a0f5462664dbcd987                 
    
    Kotlin DSL:   1.0.4                                                    
    Kotlin:       1.3.10                                                   
    Groovy:       2.5.4                                                    
    Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018   
    JVM:          11.0.1 (Oracle Corporation 11.0.1+13)                    
    OS:           Windows 10 10.0 amd64
    
    
    > java -version                                                     
    openjdk version "11.0.1" 2018-10-16                          
    OpenJDK Runtime Environment 18.9 (build 11.0.1+13)           
    OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)  
    

    两台计算机上的全局 gradle.properties 文件完全相同(并且没有任何项目本地 gradle.properties 文件):


    org.gradle.daemon=true
    org.gradle.jvmargs=-Xmx1536m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
    org.gradle.parallel=true
    

    (不带注释)


    更新 1:

    当Gradle JVM设置为JDK 8时,没有问题。但是在使用JDK 9+时,您会遇到此问题。


    更新 2:

    我将Kotlin插件从1.3.10升级到1.3.11。同时,测试了1.3.20-eap-52。但问题仍然存在。


    更新 3:

    我运行了Gradle的compileKotlin任务,并使用--debug选项获取更多信息。输出中最重要的部分如下:

    注意: 当Gradle守护进程正在运行、Kotlin编译守护进程被停止(如果已经运行)且对Kotlin源文件进行了小幅更改时,已运行以下任务。

    I. 在使用JDK 8作为Gradle JVM时 (正常):

    11:01:44 PM: Executing task 'compileKotlin --debug'...
    ...
    22:58:20.512 [DEBUG] [org.gradle.api.Project] [KOTLIN] Kotlin compiler args: -Xadd-compiler-builtins -Xbuild-file=C:\Users\I\AppData\Local\Temp\kjps3085207010700515672GradleKotlinJVM.script.xml -classpath D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jdk8\1.3.10\71d0fa967493eb76648b575edf1762cb2d0c7f10\kotlin-stdlib-jdk8-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jdk7\1.3.10\4d147bf43060dc43d61b096e24da1e67dfe0c032\kotlin-stdlib-jdk7-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib\1.3.10\b178c1501609c6e4ee8be635513cb023a466457d\kotlin-stdlib-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-common\1.3.10\1b19d99229dcedad7caf50534dce38fe82845269\kotlin-stdlib-common-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains\annotations\13.0\919f0dfe192fb4e063e7dacadee7f8bb9a2672a9\annotations-13.0.jar -d D:\Devel\IdeaProjects\GradleKotlinJVM\build\classes\kotlin\main -jvm-target 1.8 -Xload-builtins-from-dependencies -module-name GradleKotlinJVM -no-reflect -no-stdlib -Xplugin=D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-scripting-compiler-embeddable\1.3.10\e96a6125793c4ab0258119fcdce9d182f42d32b0\kotlin-scripting-compiler-embeddable-1.3.10.jar -verbose
    ...
    22:58:33.515 [INFO] [org.gradle.api.Task] i: found daemon on port 17519 (270393 ms old), trying to connect
    22:58:33.515 [INFO] [org.gradle.api.Task] i: cannot connect to registry: Connection refused: connect
    22:58:33.515 [INFO] [org.gradle.api.Task] i: found fresh run file 'C:\Users\I\AppData\Local\kotlin\daemon\kotlin-daemon.2019-01-06T19-23-50.118Z.ef9f56f7564e12d191d0ba8e50b581f8.17519.run' (270393 ms old), but no daemon, ignoring it
    22:58:33.515 [INFO] [org.gradle.api.Task] i: found daemon on port 17502 (63606 ms old), trying to connect
    22:58:33.515 [INFO] [org.gradle.api.Task] i: cannot connect to registry: Connection refused: connect
    22:58:33.515 [INFO] [org.gradle.api.Task] i: found fresh run file 'C:\Users\I\AppData\Local\kotlin\daemon\kotlin-daemon.2019-01-06T19-27-16.900Z.ef9f56f7564e12d191d0ba8e50b581f8.17502.run' (63606 ms old), but no daemon, ignoring it
    22:58:33.515 [INFO] [org.gradle.api.Task] i: starting the daemon as: C:\Program Files\Java\openjdk1.8.0_202\jre\bin\java -cp D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-compiler-embeddable\1.3.10\adc9e577de39fba3db6d60662892118afedd713\kotlin-compiler-embeddable-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-reflect\1.3.10\dd02865be0351707554b16a896b766b2396cdafa\kotlin-reflect-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib\1.3.10\b178c1501609c6e4ee8be635513cb023a466457d\kotlin-stdlib-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-script-runtime\1.3.10\1d2bac36f99b84e1493244f12629bc0756a3ff90\kotlin-script-runtime-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-common\1.3.10\1b19d99229dcedad7caf50534dce38fe82845269\kotlin-stdlib-common-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains\annotations\13.0\919f0dfe192fb4e063e7dacadee7f8bb9a2672a9\annotations-13.0.jar;C:\Program Files\Java\openjdk1.8.0_202\lib\tools.jar -Djava.awt.headless=true -Djava.rmi.server.hostname=127.0.0.1 -Xmx1536m -XX:MaxPermSize=512m -Dkotlin.environment.keepalive org.jetbrains.kotlin.daemon.KotlinCompileDaemon --daemon-runFilesPath C:\Users\I\AppData\Local\kotlin\daemon --daemon-autoshutdownIdleSeconds=7200 --daemon-compilerClasspath D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-compiler-embeddable\1.3.10\adc9e577de39fba3db6d60662892118afedd713\kotlin-compiler-embeddable-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-reflect\1.3.10\dd02865be0351707554b16a896b766b2396cdafa\kotlin-reflect-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib\1.3.10\b178c1501609c6e4ee8be635513cb023a466457d\kotlin-stdlib-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-script-runtime\1.3.10\1d2bac36f99b84e1493244f12629bc0756a3ff90\kotlin-script-runtime-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-common\1.3.10\1b19d99229dcedad7caf50534dce38fe82845269\kotlin-stdlib-common-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains\annotations\13.0\919f0dfe192fb4e063e7dacadee7f8bb9a2672a9\annotations-13.0.jar;C:\Program Files\Java\openjdk1.8.0_202\lib\tools.jar
    22:58:33.515 [INFO] [org.gradle.api.Task] i: Received the message signalling that the daemon is ready
    22:58:33.516 [INFO] [org.gradle.api.Task] i: new daemon started, trying to find it
    22:58:33.516 [INFO] [org.gradle.api.Task] i: found daemon on port 17519 (277256 ms old), trying to connect
    22:58:33.516 [INFO] [org.gradle.api.Task] i: cannot connect to registry: Connection refused: connect
    22:58:33.516 [INFO] [org.gradle.api.Task] i: found fresh run file 'C:\Users\I\AppData\Local\kotlin\daemon\kotlin-daemon.2019-01-06T19-23-50.118Z.ef9f56f7564e12d191d0ba8e50b581f8.17519.run' (277256 ms old), but no daemon, ignoring it
    22:58:33.516 [INFO] [org.gradle.api.Task] i: found daemon on port 17502 (70469 ms old), trying to connect
    22:58:33.516 [INFO] [org.gradle.api.Task] i: cannot connect to registry: Connection refused: connect
    22:58:33.516 [INFO] [org.gradle.api.Task] i: found fresh run file 'C:\Users\I\AppData\Local\kotlin\daemon\kotlin-daemon.2019-01-06T19-27-16.900Z.ef9f56f7564e12d191d0ba8e50b581f8.17502.run' (70469 ms old), but no daemon, ignoring it
    22:58:33.516 [INFO] [org.gradle.api.Task] i: found daemon on port 17507 (70 ms old), trying to connect
    22:58:33.516 [INFO] [org.gradle.api.Task] i: connected to the daemon
    22:58:33.518 [INFO] [org.gradle.api.Project] Options for KOTLIN DAEMON: IncrementalCompilationOptions(super=CompilationOptions(compilerMode=INCREMENTAL_COMPILER, targetPlatform=JVM, reportCategories=[0, 1, 2, 3, 4], reportSeverity=3, requestedCompilationResults=[0]), areFileChangesKnown=true, modifiedFiles=[D:\Devel\IdeaProjects\GradleKotlinJVM\src\main\kotlin\Main.kt], deletedFiles=[], workingDir=D:\Devel\IdeaProjects\GradleKotlinJVM\build\kotlin\compileKotlin, customCacheVersionFileName='gradle-format-version.txt', customCacheVersion=4, multiModuleICSettings=MultiModuleICSettings(buildHistoryFile=D:\Devel\IdeaProjects\GradleKotlinJVM\build\kotlin\compileKotlin\build-history.bin, useModuleDetection=false), usePreciseJavaTracking=truelocalStateDirs=[D:\Devel\IdeaProjects\GradleKotlinJVM\build\classes\kotlin\main])
    22:58:33.524 [DEBUG] [sun.rmi.transport.tcp] Daemon worker: reuse connection
    ...
    22:58:35.428 [DEBUG] [org.gradle.api.Project] [KOTLIN] [IC] compiling with args: [-Xadd-compiler-builtins, -Xbuild-file=C:\Users\I\AppData\Local\Temp\kjps6683894818132820708GradleKotlinJVM.script.xml, -classpath, D:\Devel\IdeaProjects\GradleKotlinJVM\build\classes\kotlin\main;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jdk8\1.3.10\71d0fa967493eb76648b575edf1762cb2d0c7f10\kotlin-stdlib-jdk8-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jdk7\1.3.10\4d147bf43060dc43d61b096e24da1e67dfe0c032\kotlin-stdlib-jdk7-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib\1.3.10\b178c1501609c6e4ee8be635513cb023a466457d\kotlin-stdlib-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-common\1.3.10\1b19d99229dcedad7caf50534dce38fe82845269\kotlin-stdlib-common-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains\annotations\13.0\919f0dfe192fb4e063e7dacadee7f8bb9a2672a9\annotations-13.0.jar, -jvm-target, 1.8, -Xload-builtins-from-dependencies, -module-name, GradleKotlinJVM, -no-reflect, -no-stdlib, -Xplugin=D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-scripting-compiler-embeddable\1.3.10\e96a6125793c4ab0258119fcdce9d182f42d32b0\kotlin-scripting-compiler-embeddable-1.3.10.jar, -Xreport-output-files, -verbose]
    ...
    11:01:53 PM: Task execution finished 'compileKotlin --debug'.
    

    II. 当使用 JDK 11 作为 Gradle 的 JVM 时(这里有问题):

    11:01:44 PM: Executing task 'compileKotlin --debug'...
    ...
    23:01:45.888 [DEBUG] [org.gradle.api.Project] [KOTLIN] Kotlin compiler args: -Xadd-compiler-builtins -Xbuild-file=C:\Users\I\AppData\Local\Temp\kjps11452575260818015211GradleKotlinJVM.script.xml -classpath D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jdk8\1.3.10\71d0fa967493eb76648b575edf1762cb2d0c7f10\kotlin-stdlib-jdk8-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-jdk7\1.3.10\4d147bf43060dc43d61b096e24da1e67dfe0c032\kotlin-stdlib-jdk7-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib\1.3.10\b178c1501609c6e4ee8be635513cb023a466457d\kotlin-stdlib-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-common\1.3.10\1b19d99229dcedad7caf50534dce38fe82845269\kotlin-stdlib-common-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains\annotations\13.0\919f0dfe192fb4e063e7dacadee7f8bb9a2672a9\annotations-13.0.jar -d D:\Devel\IdeaProjects\GradleKotlinJVM\build\classes\kotlin\main -jvm-target 1.8 -Xload-builtins-from-dependencies -module-name GradleKotlinJVM -no-reflect -no-stdlib -Xplugin=D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-scripting-compiler-embeddable\1.3.10\e96a6125793c4ab0258119fcdce9d182f42d32b0\kotlin-scripting-compiler-embeddable-1.3.10.jar -verbose
    ...
    23:01:48.134 [INFO] [org.gradle.api.Task] i: starting the daemon as: C:\Program Files\Java\openjdk-11.0.1\bin\java -cp D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-compiler-embeddable\1.3.10\adc9e577de39fba3db6d60662892118afedd713\kotlin-compiler-embeddable-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-reflect\1.3.10\dd02865be0351707554b16a896b766b2396cdafa\kotlin-reflect-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib\1.3.10\b178c1501609c6e4ee8be635513cb023a466457d\kotlin-stdlib-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-script-runtime\1.3.10\1d2bac36f99b84e1493244f12629bc0756a3ff90\kotlin-script-runtime-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-common\1.3.10\1b19d99229dcedad7caf50534dce38fe82845269\kotlin-stdlib-common-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains\annotations\13.0\919f0dfe192fb4e063e7dacadee7f8bb9a2672a9\annotations-13.0.jar -Djava.awt.headless=true -Djava.rmi.server.hostname=127.0.0.1 -Xmx1536m -XX:MaxPermSize=512m -Dkotlin.environment.keepalive org.jetbrains.kotlin.daemon.KotlinCompileDaemon --daemon-runFilesPath C:\Users\I\AppData\Local\kotlin\daemon --daemon-autoshutdownIdleSeconds=7200 --daemon-compilerClasspath D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-compiler-embeddable\1.3.10\adc9e577de39fba3db6d60662892118afedd713\kotlin-compiler-embeddable-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-reflect\1.3.10\dd02865be0351707554b16a896b766b2396cdafa\kotlin-reflect-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib\1.3.10\b178c1501609c6e4ee8be635513cb023a466457d\kotlin-stdlib-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-script-runtime\1.3.10\1d2bac36f99b84e1493244f12629bc0756a3ff90\kotlin-script-runtime-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-common\1.3.10\1b19d99229dcedad7caf50534dce38fe82845269\kotlin-stdlib-common-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains\annotations\13.0\919f0dfe192fb4e063e7dacadee7f8bb9a2672a9\annotations-13.0.jar
    23:01:48.134 [INFO] [org.gradle.api.Task] i: [daemon] OpenJDK 64-Bit Server VM warning: Ignoring option MaxPermSize; support was removed in 8.0
    23:01:48.134 [INFO] [org.gradle.api.Task] i: Received the message signalling that the daemon is ready
    23:01:48.134 [INFO] [org.gradle.api.Task] i: new daemon started, trying to find it
    23:01:48.134 [INFO] [org.gradle.api.Task] i: starting the daemon as: C:\Program Files\Java\openjdk-11.0.1\bin\java -cp D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-compiler-embeddable\1.3.10\adc9e577de39fba3db6d60662892118afedd713\kotlin-compiler-embeddable-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-reflect\1.3.10\dd02865be0351707554b16a896b766b2396cdafa\kotlin-reflect-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib\1.3.10\b178c1501609c6e4ee8be635513cb023a466457d\kotlin-stdlib-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-script-runtime\1.3.10\1d2bac36f99b84e1493244f12629bc0756a3ff90\kotlin-script-runtime-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-common\1.3.10\1b19d99229dcedad7caf50534dce38fe82845269\kotlin-stdlib-common-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains\annotations\13.0\919f0dfe192fb4e063e7dacadee7f8bb9a2672a9\annotations-13.0.jar -Djava.awt.headless=true -Djava.rmi.server.hostname=127.0.0.1 -Xmx1536m -XX:MaxPermSize=512m -Dkotlin.environment.keepalive org.jetbrains.kotlin.daemon.KotlinCompileDaemon --daemon-runFilesPath C:\Users\I\AppData\Local\kotlin\daemon --daemon-autoshutdownIdleSeconds=7200 --daemon-compilerClasspath D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-compiler-embeddable\1.3.10\adc9e577de39fba3db6d60662892118afedd713\kotlin-compiler-embeddable-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-reflect\1.3.10\dd02865be0351707554b16a896b766b2396cdafa\kotlin-reflect-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib\1.3.10\b178c1501609c6e4ee8be635513cb023a466457d\kotlin-stdlib-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-script-runtime\1.3.10\1d2bac36f99b84e1493244f12629bc0756a3ff90\kotlin-script-runtime-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-common\1.3.10\1b19d99229dcedad7caf50534dce38fe82845269\kotlin-stdlib-common-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains\annotations\13.0\919f0dfe192fb4e063e7dacadee7f8bb9a2672a9\annotations-13.0.jar
    23:01:48.134 [INFO] [org.gradle.api.Task] i: [daemon] OpenJDK 64-Bit Server VM warning: Ignoring option MaxPermSize; support was removed in 8.0
    23:01:48.134 [INFO] [org.gradle.api.Task] i: Received the message signalling that the daemon is ready
    23:01:48.134 [INFO] [org.gradle.api.Task] i: new daemon started, trying to find it
    23:01:48.137 [WARN] [org.gradle.api.Project] Could not perform incremental compilation: Could not connect to Kotlin compile daemon
    23:01:48.137 [WARN] [org.gradle.api.Project] Could not connect to kotlin daemon. Using fallback strategy.
    23:01:49.486 [LIFECYCLE] [system.err] 
    23:01:49.486 [ERROR] [system.err] logging: using Kotlin home directory <no_path>
    23:01:49.521 [ERROR] [system.err] logging: configuring the compilation environment
    23:01:50.538 [ERROR] [system.err] logging: loading modules: [java.se, jdk.accessibility, jdk.attach, jdk.compiler, jdk.dynalink, jdk.httpserver, jdk.jartool, jdk.javadoc, jdk.jconsole, jdk.jdi, jdk.jfr, jdk.jshell, jdk.jsobject, jdk.management, jdk.management.jfr, jdk.net, jdk.scripting.nashorn, jdk.sctp, jdk.security.auth, jdk.security.jgss, jdk.unsupported, jdk.unsupported.desktop, jdk.xml.dom, java.base, java.compiler, java.datatransfer, java.desktop, java.xml, java.instrument, java.logging, java.management, java.management.rmi, java.rmi, java.naming, java.net.http, java.prefs, java.scripting, java.security.jgss, java.security.sasl, java.sql, java.transaction.xa, java.sql.rowset, java.xml.crypto, jdk.internal.jvmstat, jdk.management.agent, jdk.jdwp.agent, jdk.internal.ed, jdk.internal.le, jdk.internal.opt]
    23:01:53.459 [ERROR] [system.err] warning: the '-d' option with a directory destination is ignored because '-Xbuild-file' is specified
    ...
    11:01:53 PM: Task execution finished 'compileKotlin --debug'.
    

    III. 当使用 JDK 11 作为 Gradle 的 JVM,但在 Linux 上(OK):

    $ ./gradlew compileKotlin --debug
    ...
    01:33:20.145 [INFO] [org.gradle.api.Task] i: starting the daemon as: /usr/local/jdk-11.0.1/bin/java -cp /usr/share/nginx/html/0xy/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-compiler-embeddable/1.3.10/adc9e577de39fba3db6d60662892118afedd713/kotlin-compiler-embeddable-1.3.10.jar:/usr/share/nginx/html/0xy/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-reflect/1.3.10/dd02865be0351707554b16a896b766b2396cdafa/kotlin-reflect-1.3.10.jar:/usr/share/nginx/html/0xy/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.3.10/b178c1501609c6e4ee8be635513cb023a466457d/kotlin-stdlib-1.3.10.jar:/usr/share/nginx/html/0xy/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-script-runtime/1.3.10/1d2bac36f99b84e1493244f12629bc0756a3ff90/kotlin-script-runtime-1.3.10.jar:/usr/share/nginx/html/0xy/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.3.10/1b19d99229dcedad7caf50534dce38fe82845269/kotlin-stdlib-common-1.3.10.jar:/usr/share/nginx/html/0xy/.gradle/caches/modules-2/files-2.1/org.jetbrains/annotations/13.0/919f0dfe192fb4e063e7dacadee7f8bb9a2672a9/annotations-13.0.jar -Djava.awt.headless=true -Djava.rmi.server.hostname=127.0.0.1 -Xmx1536m -XX:MaxPermSize=512m -Dkotlin.environment.keepalive org.jetbrains.kotlin.daemon.KotlinCompileDaemon --daemon-runFilesPath /usr/share/nginx/html/0xy/.kotlin/daemon --daemon-autoshutdownIdleSeconds=7200 --daemon-compilerClasspath /usr/share/nginx/html/0xy/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-compiler-embeddable/1.3.10/adc9e577de39fba3db6d60662892118afedd713/kotlin-compiler-embeddable-1.3.10.jar:/usr/share/nginx/html/0xy/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-reflect/1.3.10/dd02865be0351707554b16a896b766b2396cdafa/kotlin-reflect-1.3.10.jar:/usr/share/nginx/html/0xy/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.3.10/b178c1501609c6e4ee8be635513cb023a466457d/kotlin-stdlib-1.3.10.jar:/usr/share/nginx/html/0xy/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-script-runtime/1.3.10/1d2bac36f99b84e1493244f12629bc0756a3ff90/kotlin-script-runtime-1.3.10.jar:/usr/share/nginx/html/0xy/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.3.10/1b19d99229dcedad7caf50534dce38fe82845269/kotlin-stdlib-common-1.3.10.jar:/usr/share/nginx/html/0xy/.gradle/caches/modules-2/files-2.1/org.jetbrains/annotations/13.0/919f0dfe192fb4e063e7dacadee7f8bb9a2672a9/annotations-13.0.jar
    01:33:20.145 [INFO] [org.gradle.api.Task] i: [daemon] OpenJDK 64-Bit Server VM warning: Ignoring option MaxPermSize; support was removed in 8.0
    01:33:20.145 [INFO] [org.gradle.api.Task] i: Received the message signalling that the daemon is ready
    01:33:20.145 [INFO] [org.gradle.api.Task] i: new daemon started, trying to find it
    01:33:20.145 [INFO] [org.gradle.api.Task] i: found daemon on port 17613 (56 ms old), trying to connect
    01:33:20.145 [INFO] [org.gradle.api.Task] i: connected to the daemon
    01:33:20.145 [INFO] [org.gradle.api.Project] Options for KOTLIN DAEMON: IncrementalCompilationOptions(super=CompilationOptions(compilerMode=INCREMENTAL_COMPILER, targetPlatform=JVM, reportCategories=[0, 1, 2, 3, 4], reportSeverity=3, requestedCompilationResults=[0]), areFileChangesKnown=false, modifiedFiles=null, deletedFiles=null, workingDir=/usr/share/nginx/html/0xy/test/build/kotlin/compileKotlin, customCacheVersionFileName='gradle-format-version.txt', customCacheVersion=4, multiModuleICSettings=MultiModuleICSettings(buildHistoryFile=/usr/share/nginx/html/0xy/test/build/kotlin/compileKotlin/build-history.bin, useModuleDetection=false), usePreciseJavaTracking=truelocalStateDirs=[/usr/share/nginx/html/0xy/test/build/classes/kotlin/main])
    ...
    01:33:21.920 [DEBUG] [org.gradle.api.Project] [KOTLIN] [IC] compiling with args: [-Xadd-compiler-builtins, -Xbuild-file=/tmp/kjps15100965302804914597GradleKotlinJVM.script.xml, -classpath, /usr/share/nginx/html/0xy/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.3.10/71d0fa967493eb76648b575edf1762cb2d0c7f10/kotlin-stdlib-jdk8-1.3.10.jar:/usr/share/nginx/html/0xy/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.3.10/4d147bf43060dc43d61b096e24da1e67dfe0c032/kotlin-stdlib-jdk7-1.3.10.jar:/usr/share/nginx/html/0xy/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.3.10/b178c1501609c6e4ee8be635513cb023a466457d/kotlin-stdlib-1.3.10.jar:/usr/share/nginx/html/0xy/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.3.10/1b19d99229dcedad7caf50534dce38fe82845269/kotlin-stdlib-common-1.3.10.jar:/usr/share/nginx/html/0xy/.gradle/caches/modules-2/files-2.1/org.jetbrains/annotations/13.0/919f0dfe192fb4e063e7dacadee7f8bb9a2672a9/annotations-13.0.jar, -jvm-target, 1.8, -Xload-builtins-from-dependencies, -module-name, GradleKotlinJVM, -no-reflect, -no-stdlib, -Xplugin=/usr/share/nginx/html/0xy/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-scripting-compiler-embeddable/1.3.10/e96a6125793c4ab0258119fcdce9d182f42d32b0/kotlin-scripting-compiler-embeddable-1.3.10.jar, -Xreport-output-files, -verbose]
    ...
    

    上述日志中有一些可疑事件(第二个日志),但我无法确切理解它们的含义,也不知道它们是否与我的问题有关:

    1. 为什么会出现两次(完全相同)尝试来启动 Kotlin编译守护进程
    2. 虽然存在一些错误,但它们都是在 Kotlin 守护程序问题的警告之后出现的。
    3. 最新的错误/警告信息:

      [ERROR] [system.err] warning: the '-d' option with a directory destination is ignored because '-Xbuild-file' is specified
      

      最可疑的就是它!因为这是你在其他日志中找不到的唯一消息。另请参见此处。我在另一个帖子中也问了这个问题。

    5个回答

    30

    最终,经过几天的努力,我找到了问题的源头...

    我发现问题来自于我的用户帐户。于是决定将任何与用户相关的内容还原为其最初状态。在清除 AppData\local\ 中的 Temp 文件夹时,我意外地看到了这些文件:

    kotlin-daemon.Û²Û°Û±Û¹-Û°Û±-Û°Û¸.Û°Û³-ÛµÛ´-Û±Û²-Û¶Û´Û¸.00.log
    kotlin-daemon.Û²Û°Û±Û¹-Û°Û±-Û°Û¸.Û°Û³-ÛµÛ´-Û±Û²-Û¶Û´Û¸.00.log
    

    是的!问题出在Unicode编码问题上(可能是NTFS和UTF-8之间)!虽然这些是log文件,也许不重要,但这个问题可能存在于其他地方!

    正如你所猜到的,文件名的损坏部分是日期时间。所以(不幸的是),我被迫将个人化的Windows用户帐户的日期和时间格式从我最喜欢的(波斯语(伊朗))恢复为英语(美国)

    输入图像说明

    问题立刻解决:

    > wmic process where "name='java.exe'" get processId, executablePath, commandLine /format:list
    
    CommandLine=D:\Devel\JDK\openjdk-11.0.1\bin\java.exe -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED -Xmx1536m -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -cp D:\Devel\.gradle\wrapper\dists\gradle-5.0-all\4mxuau4c77thx8zlvtz4xiez7\gradle-5.0\lib\gradle-launcher-5.0.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 5.0
    ExecutablePath=D:\Devel\JDK\openjdk-11.0.1\bin\java.exe
    ProcessId=9168
    
    CommandLine=D:\Devel\JDK\openjdk-11.0.1\bin\java -cp D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-compiler-embeddable\1.3.10\adc9e577de39fba3db6d60662892118afedd713\kotlin-compiler-embeddable-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-reflect\1.3.10\dd02865be0351707554b16a896b766b2396cdafa\kotlin-reflect-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib\1.3.10\b178c1501609c6e4ee8be635513cb023a466457d\kotlin-stdlib-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-script-runtime\1.3.10\1d2bac36f99b84e1493244f12629bc0756a3ff90\kotlin-script-runtime-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-common\1.3.10\1b19d99229dcedad7caf50534dce38fe82845269\kotlin-stdlib-common-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains\annotations\13.0\919f0dfe192fb4e063e7dacadee7f8bb9a2672a9\annotations-13.0.jar -Djava.awt.headless=true -Djava.rmi.server.hostname=127.0.0.1 -Xmx1536m -XX:MaxPermSize=512m -Dkotlin.environment.keepalive org.jetbrains.kotlin.daemon.KotlinCompileDaemon --daemon-runFilesPath C:\Users\I\AppData\Local\kotlin\daemon --daemon-autoshutdownIdleSeconds=7200 --daemon-compilerClasspath D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-compiler-embeddable\1.3.10\adc9e577de39fba3db6d60662892118afedd713\kotlin-compiler-embeddable-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-reflect\1.3.10\dd02865be0351707554b16a896b766b2396cdafa\kotlin-reflect-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib\1.3.10\b178c1501609c6e4ee8be635513cb023a466457d\kotlin-stdlib-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-script-runtime\1.3.10\1d2bac36f99b84e1493244f12629bc0756a3ff90\kotlin-script-runtime-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-common\1.3.10\1b19d99229dcedad7caf50534dce38fe82845269\kotlin-stdlib-common-1.3.10.jar;D:\Devel\.gradle\caches\modules-2\files-2.1\org.jetbrains\annotations\13.0\919f0dfe192fb4e063e7dacadee7f8bb9a2672a9\annotations-13.0.jar
    ExecutablePath=D:\Devel\JDK\openjdk-11.0.1\bin\java.exe
    ProcessId=12088
    

    第二个进程是Kotlin编译守护进程


    还有日志文件:

    kotlin-daemon.2019-01-08.03-51-11-111.00.log
    kotlin-daemon.2019-01-08.03-51-11-111.00.log.lck
    

    (请注意,.log.lck文件在之前的状态中不存在!)


    成功了!希望他们在以后的版本中进行更改。 - Ahmad Reza Enshaee
    是的!俄罗斯格式导致了相同的错误。 - undefined

    5
    在我的情况下,我通过清除用户文件夹中的一些缓存来解决了问题,特别是:
    C:\Users\user\.android\build-cache\
    C:\Users\user\.android\cache\
    C:\Users\user\.gradle\caches\
    

    不确定哪个起了作用,但在清除所有内容后,错误消失了。


    没有帮助。可能无关。 - Ace
    已清除第一和第二项,这有所帮助,谢谢。 - mxkmn

    3
    我知道这个问题有答案,但当我尝试同样的方法时,项目仍然报了同样的错误:
    “无法连接到Kotlin守护进程”
    但后来我通过进入Android Studio的终端并运行以下代码解决了这个问题:`.\gradlew --stop`。之后我清理了项目并重新运行,问题得到了解决,我成功下载了应用程序。 希望有人看到这个并能解决他们的问题。

    停止守护进程并停止1个,然后重新构建,大功告成。谢谢。 - undefined

    1
    我将kotlin从 ext.kotlin_version = '1.4.32' 降级到 ext.kotlin_version = '1.3.50',问题已解决。

    0
    重启ADB对我来说起作用了。只需在终端上运行以下命令即可:
    adb kill-server
    adb start-server
    

    网页内容由stack overflow 提供, 点击上面的
    可以查看英文原文,
    原文链接