I am trying to create an intellij plugin which automatically attaches a facet to my root project module whenever a new project is created.
I have tried to create the facet in the setupProject step of my NewProjectWizardStep but there was no modules available (Presumably the root module has yet to be created). I am using the new project wizard API if that matters.
val moduleManager = ModuleManager.getInstance(project) val modules = moduleManager.modules // This is empty so the code below doesn't run if (modules.isNotEmpty()) { val module = modules[0] val facetManager = FacetManager.getInstance(module) val facetModel = facetManager.createModifiableModel() val facetType = FacetType.findInstance(GhidraFacetType::class.java) val facet = facetManager.createFacet(facetType, "Ghidra", null) facetModel.addFacet(facet) facetModel.commit() }
I would recommend not designing the settings this way. Facets should be created by users only when some manual customization is needed.
There are numerous ways how modules appear in project:
created via UI
imported from Gradle/Maven
loaded from .iml on VCS update
It is super hard to cover all those cases and make something consistent.
Previously, IntelliJ IDEA used some auto-import of facets, for Spring and JPA technologies. It was implemented as import handler for Gradle/Maven to make sure it always in sync with build settings. Nowadays, we don’t do that, we auto-discover and cache such automatic settings if there are no facets - making features always available without excessive configuration. Facets are considered only user-overrides / customizations then.
We also do not introduce any new facet types now, prefer technology-native configuration or Project settings instead.
As you may notice Facets exist only in IntelliJ IDEA and do not exist in other JetBrains IDEs
If so, then what is your recommendation to implement logic where a user creates a new custom project and is able to automatically have some SDKs loaded?
Will it be sufficient to create a root module and library during new project creation and add the library as a dependency to the root module?
Sorry got a little confused previously. I was referring to a bunch of library (JAR) files. The library files are essential for development of the Java framework the plugin is for. Ideally i will want to automatically include these jar files during project creation so the user do not have to do so manually.
The previous developer of the plugin added the JAR files via a facet but considering what you mentioned it seems that it wouldn’t be necessary.
As far as I know you do not need facet to attach JARs and class directories to Java module .iml configuration. You probably can use ModuleRootManager.getModifiableModel() and also check how IntelliJ IDEA Community Java support adds new class directories from UI.