How to get the list modules directory present in project ?

Answered

Is there  any way to get the path of all Modules(Java projects) which I have imported in IntelliJ-J idea Project , using plain java method  or IntelliJ save this information in any file ?  basically I want to get the list of directory path which is present in my IntelliJ-J project

 

I want to get Test Module path and Yaho Module path i.e  C:\Users\{}\Desktop\ … and  R:\Rightscale\yahao  , using simple java project is there any possible way ?

 

Something like :

public static void main(String[] args) throws Exception{

            { code to get the Module Location }

      }

0
8 comments

See `.idea/modules.xml` file for the module paths.

0
Avatar
Permanently deleted user

Thanks Serge , but there is no such xml present inside the .idea folder  attached image of all available xml present inside the .idea folder 

0

You need to enable Settings (Preferences on macOS) | Build, Execution, Deployment | Build Tools | Gradle | Generate *.iml files for modules imported from Gradle option.

0
Avatar
Permanently deleted user

But Directories path will always be present inside the xml file even after removing the module ( <option name="path" value="R:/Rightscale/yaho" /> i removed this Yaho  module , but its still present inside the xml file ).

Is there any to to get the directory path only for those modules which are present inside the open project . 

0

Sync the project with Gradle, it will reflect modules present in Gradle project: https://stackoverflow.com/a/43192764/104891.

0
Avatar
Permanently deleted user

After reading some documentation , I am able to get the list of all Modules present inside a project by using below code ;:

DataContext dataContext = DataManager.getInstance().getDataContext();
Project project = (Project) dataContext.getData(DataConstants.PROJECT);

String projectName = project.getName();
VirtualFile[] vFiles = ProjectRootManager.getInstance(project).getContentRootsFromAllModules();
String sourceRootsList = Arrays.stream(vFiles).map(VirtualFile::getUrl).collect(Collectors.joining("\n"));
System.out.println("----------->"+sourceRootsList);


it gives me the Directory path of all Modules. it works perfectly fine in IntelliJ Idea Plugin Development , I want to use the same code in normal java project , not as Plugin.

To get the dependencies , I have added : id 'org.jetbrains.intellij' version '0.4.21' in my build.gradle file , but its not
working giving error :

error: cannot access DataManager
import com.intellij.ide.DataManager;
^
bad class file: C:\Users\{***}\.gradle\caches\modules-2\files-2.1\com.jetbrains.intellij.idea\ideaIC\LATEST-EAP-SNAPSHOT\d35b46d7a3f1e014666ab20772197510c33671ef\ideaIC-LATEST-EAP-SNAPSHOT\lib\platform-api.jar(com/intellij/ide/DataManager.class)
class file has wrong version 55.0, should be 52.0
Please remove or make sure it appears in the correct subdirectory of the classpath.

 

Can we use plugin code in plain java code by adding compile time dependency ? if yes then  Where i make mistake in above code ?

0

No, this code can be used only from a plug-in.

1
Avatar
Permanently deleted user

Thanks Serge ...  !!

1

Please sign in to leave a comment.