Fix initializeIntelliJPlugin timeout

When running the plugin, the initializeIntelliJPlugin task always waits for a long time before proceeding to the next step.

When developing plugins, the common tasks are Run / Debug / Build gradle tasks, but they always get stuck on the initializeIntelliJPlugin task for a long time.

Locate the problem

Here is the source code of InitializeIntelliJPluginTask.kt file.

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.DefaultTask
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.UntrackedTask
import org.jetbrains.intellij.*
import org.jetbrains.intellij.IntelliJPluginConstants.PLUGIN_GROUP_NAME
import 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)
}
}
}

It mainly does one thing: checkPluginVersion(), so it is likely because of the network connection. In other words, if the connection to the server is slow, this problem may occur.

Solve the problem

In the checkPluginVersion() method, there is a judgment condition. As long as selfUpdateCheck is set to false or offline is set to true, it can avoid checking. Now the problem is very easy to solve. As long as one of the above conditions is met.

In the build.gradle.kts file, add the following code to solve the problem.

tasks {
...
initializeIntelliJPlugin {
selfUpdateCheck.set(false)
}
...
}

Categories : IntelliJ Plugin