Add custom vm options in Plugin.
Answered
I am currently developing a plugin which requires a JVM argument to interact with a custom API. However, I am struggling to understand how to set this argument directly from the plugin itself.
In the build.gradle.kts, I added:
tasks.withType<JavaExec>().configureEach {
jvmArgs( "myArgument")
}
This configuration successfully works in the “Run Plugin” scenario. However, when I install the ZIP file in the IDE through the buildPlugin task, the VM fails to recognize the option.
Could you provide some assistance on the proper way to set this JVM argument from a plugin? Any guidance would be greatly appreciated.
Best Regards,
Andrei
Please sign in to leave a comment.
Hi Andrei,
Setting these properties in the Gradle task will take effect only while executing this task, so during development only.
You cannot change JVM arguments from the plugin, as they are provided while the IDE application is started. Plugins are loaded into the IDE, they are not started as separate Java processes.
Hi Karol,
Thanks for the quick reply. What if I configure the plugin to request an IDE restart after being installed, so that the vm options file to be changed? Also, I see there is a plugin that actually does that: https://plugins.jetbrains.com/plugin/17633-jvm-arguments-setter
Regards,
Andrei
As far as I understand, this plugin modifies JVM arguments for processes started from the IDE via run/debug configurations. It doesn't change the IDE JVM arguments.
The idea of changing the JVM arguments by plugin and requesting the restart sounds really bad from the UX point of view, and also plugins must not modify any IDE system options.
Please explain why JVM argument is a must in your case. Maybe there is another way to achieve what you need.
Hi Karol,
We reach the following exception:
java.lang.ExceptionInInitializerError: Exception java.lang.IllegalAccessError: class com.jidesoft.plaf.LookAndFeelFactory (in unnamed module @0x249a29f2) cannot access class com.sun.java.swing.plaf.windows.WindowsLookAndFeel (in module java.desktop) because module java.desktop does not export com.sun.java.swing.plaf.windows to unnamed module @0x249a29f2 [in thread "AWT-EventQueue-0"]
The current workaround is to set a JVM option such as:
--add-opens=java.desktop/com.sun.java.swing.plaf.windows=ALL-UNNAMED
Please let me know if you know a better solution for this.
Regards,
Florin
Unfortunately there is no “clean” solution to modify IDE VM arguments for a plugin. If possible, try to avoid using custom L&F/components in your plugin.