How to get project resource roots

Hello, for example in PhpStorm it’s possible to mark a directory as a Resource Root or Source Root, etc. What’s the best way to obtain the list of resource roots in my plugin?

ModuleRootManager and also ProjectRootManager should provide what you need.

There’s BaseProjectDirectories if you’re only interested in the top-level directories of a project.

Thank you, I tested it and nothing returns my folder www. I see in list only project root directory and source roots (I have not excluded folder). But my resource root folder is not here.

Here is my test code:

val list = mutableListOf<VirtualFile>()
list.addAll(project.getBaseDirectories())
list.addAll(ProjectRootManager.getInstance(project).contentRoots.toList())
list.addAll(ProjectRootManager.getInstance(project).contentSourceRoots)
list.addAll(ProjectRootManager.getInstance(project).getModuleSourceRoots(setOf(JavaResourceRootType.RESOURCE)))

project.modules.forEach {
    list.addAll(ModuleRootManager.getInstance(it).contentRoots)
    list.addAll(ModuleRootManager.getInstance(it).sourceRoots)
    list.addAll(ModuleRootManager.getInstance(it).excludeRoots)
    list.addAll(ModuleRootManager.getInstance(it).getSourceRoots(JavaResourceRootType.RESOURCE))
}