Best practice: how to add optional Rider support in gradle build

Hi,
I have a plugin that’s compatible with all IDEs, but I need to add some code just for Rider.

Context: I need to open projects programmatically (basically, I have a Favorite Projects manager). I do that via ProjectManager.getInstance().loadAndOpenProject(projectPath). It works on all IDEs, except in Rider. I opened RIDER-139440, but I need a (temporary) workaround asap. I found how Rider actually opens projects, and it’s using APIs that are specific to Rider.
So, I will add some optional code just for this IDE.

Let’s say I’m using the official intellij-platform-plugin-template. I support 251+ IDEs, but I can change it if needed. I don’t support the split mode for now.
I know what to do in plugin.xml: something like <depends optional="true" config-file="plugin-rider.xml">com.intellij.modules.rider</depends>.
→ I would need some advice for my build.gradle.kts. I could build against Rider (intellijPlatform { create("RD", ...)}), but I would like to continue to work with IJ.
I think a solution would be to create a gradle module for Rider.

I’d like to know your opinion before moving forward. Thx.

Try using com.intellij.ide.impl.ProjectUtil#openOrImportAsync — that method is Rider-friendly, and I think is compatible with all the other IDEs as well, so you won’t need a Rider-specific module.

If you still need a Rider-specific module for some reason, though, then my recommendation would be to use plugin modules.

Check here how to create a modular plugin — each of the modules can have a separate dependencies set, and even depend on different IDEs. When loading the plugin, only the modules whose dependencies are satisfied will be loaded. This allows you to pack IDE-specific modules into the same plugin with essentially no downsides.

Note that most likely you won’t need it and ProjectUtil will resolve the issue.

It’s like I cannot use it from Java, probably because this is a suspended function. I tested openOrImport instead, and it works. In Rider, it asks whether to open as a simple folder or select the .sln file, but that’s okay. In IJ, it opens the project directly.
Thank you!

[edit] Is it better if I use the path of the .sln file directly.