Repository: TheBlob42/idea-which-key
Pull request #95: Migrate to gradle plugin v2
Author: login: luqasn
Created: 2025-02-28T22:26:45Z | Merged: 2025-03-08T19:52:33Z

Hi, I took the time to move away from the now unsupported v1 gradle api.

Doesn't seem to bring many benefits that I can see, but in their blogpost they say migrating is important :P

https://blog.jetbrains.com/platform/2024/07/intellij-platform-gradle-plugin-2-0/

It also fixes an error that I had on my machine with kotlin/java having different jvm versions specified.


Diff:
diff --git a/.gitignore b/.gitignore
index 2e60b5c..d33a166 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
 .idea/
 .gradle/
 build/
-out/
\ No newline at end of file
+out/
+.intellijPlatform
\ No newline at end of file
diff --git a/build.gradle.kts b/build.gradle.kts
index 953c7f6..d7d3783 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -1,10 +1,8 @@
-import org.jetbrains.intellij.tasks.PatchPluginXmlTask
-import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
 
 plugins {
     java
     kotlin("jvm") version "1.9.22"
-    id("org.jetbrains.intellij") version "1.16.1"
+    id("org.jetbrains.intellij.platform") version "2.3.0"
 }
 
 group = "eu.theblob42.idea.whichkey"
@@ -12,6 +10,9 @@ version = "0.10.3"
 
 repositories {
     mavenCentral()
+    intellijPlatform {
+        defaultRepositories()
+    }
 }
 
 dependencies {
@@ -19,19 +20,52 @@ dependencies {
     implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.6.4")
 
     testImplementation("junit", "junit", "4.12")
+
+    intellijPlatform {
+        intellijIdeaCommunity("2023.3.3")
+        pluginVerifier()
+        plugins("IdeaVIM:2.10.0")
+    }
 }
 
-tasks.withType<KotlinCompile> {
-    kotlinOptions.jvmTarget = "17"
+intellijPlatform {
+    pluginConfiguration {
+        ideaVersion {
+            // Let the Gradle plugin set the since-build version. It defaults to the version of the IDE we're building against
+            // specified as two components, `{branch}.{build}` (e.g., "241.15989"). There is no third component specified.
+            // The until-build version defaults to `{branch}.*`, but we want to support _all_ future versions, so we set it
+            // with a null provider (the provider is important).
+            // By letting the Gradle plugin handle this, the Plugin DevKit IntelliJ plugin cannot help us with the "Usage of
+            // IntelliJ API not available in older IDEs" inspection. However, since our since-build is the version we compile
+            // against, we can never get an API that's newer - it would be an unresolved symbol.
+            untilBuild.set(provider { null })
+        }
+    }
+
 }
 
-tasks.withType<PatchPluginXmlTask> {
-    sinceBuild.set("233")
+java {
+    toolchain {
+        languageVersion.set(JavaLanguageVersion.of(17))
+    }
 }
 
-// See https://github.com/JetBrains/gradle-intellij-plugin/
-intellij {
-    version.set("2023.3.3")
-    updateSinceUntilBuild.set(false)
-    plugins.set(listOf("IdeaVIM:2.10.0"))
+kotlin {
+    jvmToolchain {
+        languageVersion.set(JavaLanguageVersion.of(17))
+    }
+}
+
+tasks {
+    compileKotlin {
+        kotlinOptions {
+            jvmTarget = "17"
+        }
+    }
+
+    compileTestKotlin {
+        kotlinOptions {
+            jvmTarget = "17"
+        }
+    }
 }


Reviews:
user: login: luqasn
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-02-28T22:28:22Z
user: login: TheBlob42
state: COMMENTED
author_association: OWNER
submitted_at: 2025-03-08T15:59:36Z
user: login: luqasn
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-08T16:41:41Z

Review comments:
diff_hunk: @@ -1,37 +1,71 @@
-import org.jetbrains.intellij.tasks.PatchPluginXmlTask
-import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
 
 plugins {
     java
     kotlin("jvm") version "1.9.22"
-    id("org.jetbrains.intellij") version "1.16.1"
+    id("org.jetbrains.intellij.platform") version "2.3.0"
 }
 
 group = "eu.theblob42.idea.whichkey"
 version = "0.10.3"
 
 repositories {
     mavenCentral()
+    intellijPlatform {
+        defaultRepositories()
+    }
 }
 
 dependencies {
     implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.21")
     implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.6.4")
 
     testImplementation("junit", "junit", "4.12")
+
+    intellijPlatform {
+        intellijIdeaCommunity("2023.3.3")
+        pluginVerifier()
+        plugins("IdeaVIM:2.10.0")
+    }
 }
 
-tasks.withType<KotlinCompile> {
-    kotlinOptions.jvmTarget = "17"
+intellijPlatform {
+    pluginConfiguration {
+        ideaVersion {
path: build.gradle.kts
user: login: luqasn
body: this is a [copy/paste](https://github.com/search?q=%22Let+the+Gradle+plugin+set+the+since-build+version.%22&type=code) from `ideavim` and `ideavim-easymotion`. Maybe you can check if the metadata is still correctly set after building the plugin.
created_at: 2025-02-28T22:28:22Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,4 @@
+package eu.theblob42.idea.whichkey.config
+
+import org.junit.jupiter.api.Assertions.*
+ class PopupConfigCodeTest
path: src/test/kotlin/eu/theblob42/idea/whichkey/config/PopupConfigCodeTest.kt
user: login: TheBlob42
body: Did you add this new file by accident to this PR?
created_at: 2025-03-08T15:59:36Z
author_association: OWNER
diff_hunk: @@ -0,0 +1,4 @@
+package eu.theblob42.idea.whichkey.config
+
+import org.junit.jupiter.api.Assertions.*
+ class PopupConfigCodeTest
path: src/test/kotlin/eu/theblob42/idea/whichkey/config/PopupConfigCodeTest.kt
user: login: luqasn
body: Oops, yes
created_at: 2025-03-08T16:41:40Z
author_association: CONTRIBUTOR

PR comments:
user: login: TheBlob42
created_at: 2025-03-08T16:17:57Z
body: Got the following warning while building with the new file:
```
- The IntelliJ Platform cache directory should be excluded from the version control system. Add the '.intellijPlatform' entry to the '.gitignore' file.
```

Could you add this to this PR?
author_association: OWNER
user: login: luqasn
created_at: 2025-03-08T16:44:10Z
body: > Got the following warning while building with the new file:
> 
> ```
> - The IntelliJ Platform cache directory should be excluded from the version control system. Add the '.intellijPlatform' entry to the '.gitignore' file.
> ```
> 
> Could you add this to this PR?

done!
author_association: CONTRIBUTOR
user: login: TheBlob42
created_at: 2025-03-08T19:52:28Z
body: Thanks for the adoptions, looks good to me :+1: 
author_association: OWNER