My colleague asked me if it is possible to resolve plugins from JetBrains Marketplace using the latest available version that matches the currently targeted IntelliJ Platform.
I know this is a recurring topic, but today I got a pretty neat idea of how to implement it in a Gradle-compatible way – here it is:
import org.jetbrains.intellij.platform.gradle.extensions.IntelliJPlatformDependenciesExtension
import org.jetbrains.intellij.pluginRepository.PluginRepositoryFactory
val IntelliJPlatformDependenciesExtension.pluginRepository by lazy {
PluginRepositoryFactory.create("https://plugins.jetbrains.com")
}
fun IntelliJPlatformDependenciesExtension.pluginsInLatestCompatibleVersion(vararg pluginIds: String) =
plugins(provider {
pluginIds.map { pluginId ->
val platformType = intellijPlatform.productInfo.productCode
val platformVersion = intellijPlatform.productInfo.buildNumber
val plugin = pluginRepository.pluginManager.searchCompatibleUpdates(
build = "$platformType-$platformVersion",
xmlIds = listOf(pluginId),
).firstOrNull()
?: throw GradleException("No plugin update with id='$pluginId' compatible with '$platformType-$platformVersion' found in JetBrains Marketplace")
"${plugin.pluginXmlId}:${plugin.version}"
}
})
I implemented that yesterday as a compatiblePlugin(id)/compatiblePlugins(ids) helper. It should be available with the upcoming IntelliJ Platform Gradle Plugin release.