在开发插件时候,常用的是 Run
/ Debug
/ Build
这几个gradle task,但是总是卡在一个名为 initializeIntelliJPlugin task很长时间。
定位问题
这里是 InitializeIntelliJPluginTask.kt 这个文件的源码
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.intellij.tasks
import org.gradle.api.DefaultTaskimport org.gradle.api.provider.Propertyimport org.gradle.api.tasks.Internalimport org.gradle.api.tasks.TaskActionimport org.gradle.api.tasks.UntrackedTaskimport org.jetbrains.intellij.*import org.jetbrains.intellij.IntelliJPluginConstants.PLUGIN_GROUP_NAMEimport org.jetbrains.intellij.utils.LatestVersionResolver
@UntrackedTask(because = "Should always be run to initialize the plugin")abstract class InitializeIntelliJPluginTask : DefaultTask() {
12 collapsed lines
@get:Internal abstract val offline: Property<Boolean>
@get:Internal abstract val selfUpdateCheck: Property<Boolean>
init { group = PLUGIN_GROUP_NAME description = "Initializes the Gradle IntelliJ Plugin" }
private val context = logCategory()
@TaskAction fun initialize() { checkPluginVersion() }
17 collapsed lines
private fun checkPluginVersion() { if (!selfUpdateCheck.get() || offline.get()) { return }
try { val version = getCurrentPluginVersion() ?.let(Version::parse) .or { Version() } val latestVersion = LatestVersionResolver.fromGitHub(IntelliJPluginConstants.PLUGIN_NAME, IntelliJPluginConstants.GITHUB_REPOSITORY) if (version < Version.parse(latestVersion)) { warn(context, "${IntelliJPluginConstants.PLUGIN_NAME} is outdated: $version. Update `${IntelliJPluginConstants.PLUGIN_ID}` to: $latestVersion") } } catch (e: Exception) { error(context, e.message.orEmpty(), e) } }}
发现它主要做了一件事情: checkPluginVersion()
,那么推测可能是因为网络链接导致的。换言之,检查的时候如果连接到服务器很慢,有可能会出现这个问题。
解决问题
在 checkPluginVersion()
这个方法的开头,有个判断条件。只要把 selfUpdateCheck
设置为 false
或者 offline
设置为 true
。就可以避免它去检查。现在问题解决起来很方便了。 只要满足以上条件之一即可。
在 build.gradle.kts 中,新增下面的代码即可解决该问题。
tasks { ... initializeIntelliJPlugin { selfUpdateCheck.set(false) } ...}
Categories : IntelliJ Plugin