diff --git a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/JpsUtils.kt b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/JpsUtils.kt index 8e2d2e3c31b..09bfedeed62 100644 --- a/idea/idea-jps-common/src/org/jetbrains/kotlin/config/JpsUtils.kt +++ b/idea/idea-jps-common/src/org/jetbrains/kotlin/config/JpsUtils.kt @@ -5,9 +5,24 @@ package org.jetbrains.kotlin.config -private const val IDE_EVENT_QUEUE_CLASS_NAME = "com.intellij.ide.IdeEventQueue" +import com.intellij.openapi.application.ApplicationManager + +private const val APPLICATION_MANAGER_CLASS_NAME = "com.intellij.openapi.application.ApplicationManager" val isJps: Boolean by lazy { - val ideEventQueueClassPath = IDE_EVENT_QUEUE_CLASS_NAME.replace('.', '/') + ".class" - {}.javaClass.classLoader.getResource(ideEventQueueClassPath) == null + /* + Normally, JPS shouldn't have an ApplicationManager class in the classpath, + but that's not true for JPS inside IDEA right now. + Though Application is not properly initialized inside JPS so we can use it as a check. + */ + return@lazy if (doesClassExist(APPLICATION_MANAGER_CLASS_NAME)) { + ApplicationManager.getApplication() == null + } else { + true + } +} + +private fun doesClassExist(fqName: String): Boolean { + val classPath = fqName.replace('.', '/') + ".class" + return {}.javaClass.classLoader.getResource(classPath) != null } \ No newline at end of file