intellij-platform-gradle-plugin icon indicating copy to clipboard operation
intellij-platform-gradle-plugin copied to clipboard

Support building and running against different IntelliJ versions

Open fcurts opened this issue 4 years ago • 5 comments

It would be very useful if there was a way to configure an IntelliJ versions for the runIde task that is different from intellij { version = ... }. For example, I might want to build against 2019.1 but also test with 2019.3.

My current solution is runIde { ideDirectory = "..." }, but this is cumbersome (not automatically downloaded, etc.).

fcurts avatar Dec 07 '19 20:12 fcurts

@fcurts I usually use a gradle property for the version of the IDE. Then you can override that property on the command line and create scripts to run different versions of the IDE.

jansorg avatar Dec 11 '19 09:12 jansorg

@jansorg The problem is that intellij { version = ... } sets both build time and run time IntelliJ version but I often need them to differ. For example, grammar-kit requires IntelliJ version >= x at build time but I want to test with IntelliJ version < x. Setting runIde.ideDirectory is inconvenient (e.g., ~/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIC/2019.2.4/a2eb13f21bdc018b64b31208823a57771b47273/ideaIC-2019.2.4) and IntelliJ isn't automatically downloaded in this case.

fcurts avatar Feb 25 '20 07:02 fcurts

@fcurts You could add a new task, which updates the ide version in the configuration phase. You could run this with gradle -PmyIdeVersion=2019.1.1 runMyIde to use 2019.1.1 at runtime and 2019.3.2 at build time and for runIde.

intellij {
  version '2019.3.2'
}

tasks.register("runMyIde") { myTask ->
  if (project.hasProperty("myIdeVersion")) {
    intellij.version project.property("myIdeVersion")
  }
  myTask.dependsOn tasks.named("runIde")
}

jansorg avatar Feb 25 '20 09:02 jansorg

@jansorg That looks like a totally unreliable/unsupported Gradle hack to me. (There is no reliable way to assign different values to the same property over the course of a build and have the right value show up in the right places. Invoking runIde also builds the plugin.) Anyways, thanks for your suggestions.

fcurts avatar Feb 25 '20 21:02 fcurts

You‘re right, this only works if no compilation is necessary because it also updates the ide version used for the build. Disregard my suggestion

jansorg avatar Feb 25 '20 21:02 jansorg

Starting with the IntelliJ Platform Gradle Plugin 2.0, it is possible to declare multiple runIde-like tasks to run different IDE instances with your plugin loaded, by extending the RunIdeTask task class:

import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType
import org.jetbrains.intellij.platform.gradle.tasks.RunIdeTask

tasks {
  val runPhpStorm by registering(RunIdeTask::class) {
    type = IntelliJPlatformType.PhpStorm
    version = "2023.2.2"
  }

  val runLocalIde by registering(RunIdeTask::class) {
    localPath = file("/Users/hsz/Applications/Android Studio.app")
  }
}

You can use type/version or localPath to specify the IDE of your choice. See: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-tasks.html#runIde

This approach can also be applied to the TestIdeTask: https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-tasks.html#testIde

hsz avatar Mar 14 '24 18:03 hsz