JetBrains / sbt-idea-plugin

Develop IntelliJ plugins with Scala and SBT
Apache License 2.0
97 stars 28 forks source link

Possible JBR issues when using runIDE? #44

Closed reibitto closed 4 years ago

reibitto commented 4 years ago

We're developing an IntelliJ plugin using Scala which is currently using gradle-intellij-plugin, but we want to migrate it over to SBT using this plugin but I'm seeing errors like this when using the runIDE task:

java.lang.NoClassDefFoundError: com/apple/eawt/AppEvent$AboutEvent
    at com.intellij.ui.mac.MacOSApplicationProvider$Worker.initMacApplication(MacOSApplicationProvider.java:57)
    at com.intellij.ui.mac.MacOSApplicationProvider.initApplication(MacOSApplicationProvider.java:42)
    at com.intellij.idea.ApplicationLoader.startApp(ApplicationLoader.kt:159)
    at com.intellij.idea.ApplicationLoader.executeInitAppInEdt(ApplicationLoader.kt:93)
    at com.intellij.idea.ApplicationLoader.access$executeInitAppInEdt(ApplicationLoader.kt:1)
    at com.intellij.idea.ApplicationLoader$initApplication$1$1.run(ApplicationLoader.kt:355)
    at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
    ...

From what I can tell this is because JBR isn't being used. When I manually set JAVA_HOME to point to JBR before running SBT, everything works as expected:

export JAVA_HOME="/Users/reibitto/Library/Preferences/IntelliJIdea2019.3/jdks/jbrsdk-11_0_5-osx-x64-b630.1/jbrsdk/Contents/Home"

Should this be handled automatically by sbt-idea-plugin? Or maybe expose an option of some kind? For example, gradle-intellj-plugin exposes a jbrVersion setting: https://github.com/JetBrains/gradle-intellij-plugin#configuration

Or is there a different way of resolving the issue that I'm seeing? FWIW, I tried runIDE on some other IntelliJ plugins based on sbt-idea-plugin that I found publicly on GitHub and I ran into the same NoClassDefFoundErrors for macOS. If it helps, this is what our current build.sbt looks like: https://github.com/reibitto/zio-intellij/blob/1247caf840f4d52c6f49fc5e19b02e2eef86cd69/build.sbt

mutcianm commented 4 years ago

Are you using any custom IDEA distribution to build your plugin against?

reibitto commented 4 years ago

We're targeting 2019.3 (IntelliJ build 193.5233.102) currently. I'm not sure if I understood your question though.

https://github.com/zio/zio-intellij/blob/1ca07fc2cf48cac9a9915ac223a2cd44d62a9ffb/build.sbt#L21-L23

mutcianm commented 4 years ago

Okay, I see from your build.sbt that you're using the default repository for downloading IJ builds. It seems that recent IDEA distributions published there do not include JBR at all. Guess I'll need to add some heuristics to try locating JBR installed by Toolbox app.

mutcianm commented 4 years ago

@reibitto Which jdk have you been using when the java.lang.NoClassDefFoundError happened? And how did you install IJ IDEA that provides jbrsdk-11_0_5-osx-x64-b630.1: via Toolbox or as a standalone application?

The exception you're facing shouldn't impact overall functionality - it simply fails to initialise Mac-specific features such as touchbar and global menu. Can you confirm this?

reibitto commented 4 years ago

I'm currently using openjdk-11.0.2.jdk.

I tried so many things that I don't 100% remember the exact steps I took to install jbrsdk-11_0_5-osx-x64-b630.1, but I'm pretty sure it was through this plugin: https://plugins.jetbrains.com/plugin/12836-choose-runtime

Oddly enough, using the plugin didn't actually solve the problem for me. After it downloaded and installed it, it only worked after I manually set JAVA_HOME to the JBR like I mentioned in my original comment.

Also, when I use plain openjdk-11.0.2.jdk, in addition to Mac-specific features not working, the plugin appears to not be fully loaded. I don't see the underlines and suggestions that zio-intellij is supposed to give. I only see the plugin working correctly with JBR.

@hmemcpy might be able to confirm as I'm pretty sure he experienced the same problems.

mutcianm commented 4 years ago

@reibitto Could you please test with the v3.5.0?

reibitto commented 4 years ago

Thanks @mutcianm. Just tried it and it seems to work. 👍

hmemcpy commented 4 years ago

I'm trying to run this locally using the new plugin, unfortunately I get:

[error] Failed to download jbr 11_0_4b520.11: org.jetbrains.sbtidea.download.FileDownloader$DownloadException: Not found (404): https://cache-redirector.jetbrains.com/jetbrains.bintray.com/intellij-jbr/jbr-11_0_4-osx-x86_64-b520.11.tar.gz

I'm using openjdk-11.0.6 (installed with adoptopenjdk11 via brew). Why/where does it pick the 11_0_4 version?

mutcianm commented 4 years ago

@hmemcpy Could you please post intellijBuild you're using? sbt-idea-plugin tries to download and install JBR that was used to build intellijBuild with, instead of searching for a first compatible one locally( see #49 ).

mutcianm commented 4 years ago

Would be great if you could test it with the most recent plugin 3.7.0 SDK(including jbr and plugins) downloading has been overhauled to eliminate installation inconsistencies

mutcianm commented 4 years ago

Starting with version 3.7.0 IDEA run configurations generated on project import should use the downloaded JBR as well.

hmemcpy commented 4 years ago

Hey, I'm sorry it took me a while to respond! I want to confirm that the latest plugin solves all my issues on both Mac and Windows! The plugin seems to be downloading all the right versions of jbr, and everything starts smoothly!

Thanks again for fixing it! My plugin is now on sbt! This issue can be closed.