Optional Plugin Dependency Failed to Compile without Plugin Registered in build.gradle.kts


Hello, I'm currently writing an IntelliJ plugin and I'm leveraging GeneratorNewProjectWizard to create new project generators for both IntelliJ and PyCharm. I'm using NewProjectWizardDirectoryGeneratorAdapter to turn that into a DirectoryProjectGenerator and registering it in plugin.xml as an optional dependency like so:


<depends optional="true" config-file="myPluginId-python.xml>com.intellij.modules.python></depends/>

myPluginId-python.xml (same folder):

<directoryProjectGenerator implementation="com.myorg.path.DirectoryProjectGeneratorClass" />

However, when I have intelli.type set to “IC” in build.gradle.kts, and I don't have “PythonCore” plugin declared in intellij.plugins, then I am unable to compile my code because NewProjectWizardDirectoryGeneratorAdapter could not be found. I want my plugin to be able to be loaded on IntelliJ (using the ModuleBuilder adapter for GeneratorNewProjectWizard) without relying on the PythonCore plugin, whilst also allowing PyCharm to have the directory generator if it is installed on that IDE instead.

I believe I've followed the documentation for declaring optional dependencies. Am I doing something wrong?


Hi Marcus,

This is expected, as com.jetbrains.python.newProject.NewProjectWizardDirectoryGeneratorAdapter is a class from Python-specific module. You can't make it work in IntelliJ IDEA without installing the Python plugin, which provides this class.

If you want to make it work in both IDEs, I suggest extending DirectoryProjectGeneratorBase (being a part of the platform) instead of NewProjectWizardDirectoryGeneratorAdapter (being a part of the Python plugin).


Karol Lewandowski Thank you for the reply!

Sorry, it was my understanding that by using optional dependencies from the docs that I could use that Python plugin's functionality only if it installed (e.g. in PyCharm) and not use that class otherwise (e.g. using the GeneratorNewProjectWizardBuilderAdapter for IDEA instead)

Is this not possible to have this behaviour in one plugin and have it be supported on both IDEs?


Sorry, I misunderstood you.

If you want to have it only working in PyCharm and not IntelliJ IDEA without the Python plugin, then you should declare PythonCore as a plugin in your build script, exactly as you did. Without it, the plugin can't be compiled, as it contains unknown class.

Everything should work as expected at runtime. Even if you build your plugin with IntelliJ IDEA with PythonCore plugin, the optional config file won't be loaded at runtime and the Python-specific class won't be loaded by classloader, when the PythonCore module is not present in the running IDE.


Alright perfect, thank you so much for the clarification!


Please sign in to leave a comment.