我还没有完全理解这一点,但是在 Preferences, Languages & Frameworks > Scalac Server 下有一些设置可能会有所帮助:
- 如果服务器空闲 <number> 分钟,则关闭服务器。
- 使用项目主目录作为编译器服务器工作目录(编译服务器将在每次编译新项目时重新启动)
- JVM SDK 用于实例化编译服务器...(当 JVM SDK 和模块 SDK 匹配时)。
IntelliJ 窗口右下方有一个小图标,指示编译服务器是否正在运行,可用于停止和启动它。
如果服务器空闲,它将关闭。它通常应该在需要时启动,但如果 JVM SDK 与模块 SDK 不匹配,则可能不会发生这种情况。增加空闲超时应该有助于降低问题的频率。将 JVM SDK 与 Module SDK 匹配应该可以解决问题,但如果您有多个项目使用不同的 SDK,则可能无法解决。
如果您经常在项目之间切换,使用项目主目录作为编译器服务器工作目录可能会有所帮助。
编辑
IntelliJ IDEA Ultimate 2016.3.2 再次遇到这个问题,但通常的干净关机和重启方法没有奏效。我整理了一些关于编译服务器如何工作的信息,在我看来,IntelliJ 正在寻找编译服务器的错误端口。如果我手动强制生成,那么我可以看到一个编译服务器正在运行,但它不是 IntelliJ 正在寻找的那个。我仍然没有解决方案,但这些信息可能会让我们更接近解决方案。
查找文件
第一步是确定 IntelliJ 存储其配置和日志文件的位置。此信息当前发布在此处:IntelliJ 目录
在我的 Mac 上,这意味着:
- 配置文件:~/Library/Preferences/IntelliJIdea2016.3/options
- 日志文件:~/Library/Logs/IntelliJIdea2016.3
编译服务器
编译服务器是一个 Java 进程,有一个很长的命令行,结尾如下:
org.jetbrains.jps.cmdline.BuildMain <host> <port> <compile-server-id> <compile-server-cache-directory>
配置选项存储在 ~/Library/Preferences/IntelliJIdea2016.3/options/scala.xml
其中一些是在 Preferences -> Languages & Frameworks -> Scala Compiler Server 对话框中配置的,但可以通过编辑文件来添加其他设置。我的目前看起来像这样:
<application>
<component name="ScalaSettings">
<option name="COMPILE_SERVER_PORT" value="59184" />
<option name="COMPILE_SERVER_ID" value="93f4589e-4707-4e20-a05a-01869045e067" />
<option name="COMPILE_SERVER_SDK" value="1.8" />
<option name="COMPILE_SERVER_MAXIMUM_HEAP_SIZE" value="2048" />
</component>
</application>
我手动添加了 COMPILER_SERVER_PORT 选项,但是对于这个版本的 IntelliJ,它用于单个编译的编译服务器具有不同的端口和 ID。不幸的是,如果我更改 COMPILER_SERVER_PORT 并重新启动 IntelliJ,则此过程使用不同的端口,所以我认为这是两个独立的实例。
在手动启动编译后,我使用此命令查找编译服务器进程:
ps -ef | grep nailgun
此命令查找 IntelliJ 使用的端口:
lsof -i | grep idea
这里还有一个日志文件:
~/Library/Logs/IntelliJIdea2016.3/idea.log
这表明有些事情不太正确:
2016-12-28 10:19:46,745 [ 50710] INFO - j.compiler.server.BuildManager - BUILDER_PROCESS [stdout]: Build process started. Classpath: /Users/richard/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/163.10154.41/IntelliJ IDEA.app/Contents/lib/jps-launcher.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home/lib/tools.jar:/Users/richard/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/163.10154.41/IntelliJ IDEA.app/Contents/lib/optimizedFileManager.jar
2016-12-28 10:59:43,958 [2447923] INFO - ij.compiler.impl.CompileDriver - COMPILATION STARTED (BUILD PROCESS)
2016-12-28 10:59:43,960 [2447925] INFO - j.compiler.server.BuildManager - Using preloaded build process to compile /Users/richard/workspace-scala
2016-12-28 10:59:44,181 [2448146] ERROR - .impl.MessageBusConnectionImpl - java.lang.NullPointerException
java.lang.RuntimeException: java.lang.NullPointerException
at com.intellij.openapi.application.impl.LaterInvocator.invokeAndWait(LaterInvocator.java:189)
at com.intellij.openapi.application.impl.ApplicationImpl.invokeAndWait(ApplicationImpl.java:662)
at com.intellij.openapi.application.impl.ApplicationImpl.invokeAndWait(ApplicationImpl.java:667)
at org.jetbrains.plugins.scala.extensions.package$$anonfun$invokeAndWait$1.apply$mcV$sp(package.scala:567)
at org.jetbrains.plugins.scala.extensions.package$.preservingControlFlow(package.scala:577)
at org.jetbrains.plugins.scala.extensions.package$.invokeAndWait(package.scala:566)
at org.jetbrains.plugins.scala.compiler.ServerMediator$$anon$1.buildStarted(ServerMediator.scala:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.util.messages.impl.MessageBusConnectionImpl.deliverMessage(MessageBusConnectionImpl.java:117)
at com.intellij.util.messages.impl.MessageBusImpl.doPumpMessages(MessageBusImpl.java:381)
at com.intellij.util.messages.impl.MessageBusImpl.pumpMessages(MessageBusImpl.java:368)
at com.intellij.util.messages.impl.MessageBusImpl.sendMessage(MessageBusImpl.java:347)
at com.intellij.util.messages.impl.MessageBusImpl.access$200(MessageBusImpl.java:42)
at com.intellij.util.messages.impl.MessageBusImpl$2.invoke(MessageBusImpl.java:230)
at com.sun.proxy.$Proxy117.buildStarted(Unknown Source)
at com.intellij.compiler.server.BuildManager$NotifyingMessageHandler.buildStarted(BuildManager.java:1435)
at com.intellij.compiler.server.DelegatingMessageHandler.buildStarted(DelegatingMessageHandler.java:18)
at com.intellij.compiler.server.DelegatingMessageHandler.buildStarted(DelegatingMessageHandler.java:18)
at com.intellij.compiler.server.BuildMessageDispatcher.sendBuildParameters(BuildMessageDispatcher.java:115)
at com.intellij.compiler.server.BuildManager.a(BuildManager.java:724)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at com.intellij.util.concurrency.BoundedTaskExecutor$2.run(BoundedTaskExecutor.java:210)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
at org.jetbrains.plugins.scala.compiler.CompileServerLauncher$$anonfun$15.apply(CompileServerLauncher.scala:282)
at org.jetbrains.plugins.scala.compiler.CompileServerLauncher$$anonfun$15.apply(CompileServerLauncher.scala:282)
at scala.collection.TraversableLike$$anonfun$filterImpl$1.apply(TraversableLike.scala:259)
at scala.collection.immutable.Set$Set3.foreach(Set.scala:145)
at scala.collection.TraversableLike$class.filterImpl(TraversableLike.scala:258)
at scala.collection.TraversableLike$class.filter(TraversableLike.scala:270)
at scala.collection.AbstractTraversable.filter(Traversable.scala:104)
at org.jetbrains.plugins.scala.compiler.CompileServerLauncher$.org$jetbrains$plugins$scala$compiler$CompileServerLauncher$$jdkChangeRequired(CompileServerLauncher.scala:282)
at org.jetbrains.plugins.scala.compiler.CompileServerLauncher.start(CompileServerLauncher.scala:56)
at org.jetbrains.plugins.scala.compiler.CompileServerLauncher.tryToStart(CompileServerLauncher.scala:41)
at org.jetbrains.plugins.scala.compiler.ServerMediator$$anon$1$$anonfun$buildStarted$2.apply$mcV$sp(ServerMediator.scala:43)
at org.jetbrains.plugins.scala.extensions.package$$anonfun$invokeAndWait$1$$anon$16.run(package.scala:569)
at com.intellij.openapi.application.TransactionGuardImpl$6.run(TransactionGuardImpl.java:318)
at com.intellij.openapi.application.impl.LaterInvocator$1.run(LaterInvocator.java:166)
at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.a(LaterInvocator.java:417)
at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.run(LaterInvocator.java:401)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at com.intellij.ide.IdeEventQueue.b(IdeEventQueue.java:843)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:679)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:391)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
2016-12-28 10:59:44,183 [2448148] ERROR - .impl.MessageBusConnectionImpl - IntelliJ IDEA 2016.3.2 Build #IU-163.10154.41
2016-12-28 10:59:44,183 [2448148] ERROR - .impl.MessageBusConnectionImpl - JDK: 1.8.0_112-release
2016-12-28 10:59:44,183 [2448148] ERROR - .impl.MessageBusConnectionImpl - VM: OpenJDK 64-Bit Server VM
2016-12-28 10:59:44,183 [2448148] ERROR - .impl.MessageBusConnectionImpl - Vendor: JetBrains s.r.o
2016-12-28 10:59:44,183 [2448148] ERROR - .impl.MessageBusConnectionImpl - OS: Mac OS X
2016-12-28 10:59:44,183 [2448148] ERROR - .impl.MessageBusConnectionImpl - Last Action: CompileDirty
2016-12-28 10:59:48,828 [2452793] INFO - lij.compiler.impl.CompilerUtil - COMPILATION FINISHED (BUILD PROCESS); Errors: 0; warnings: 1 took 4878 ms: 0 min 4sec
CompileServerLauncher.scala表明这与无法找到要使用的 JDK 8 有关,尽管如果找不到,它看起来应该会失败并显示错误消息,而不是 NullPointerException。