Automatically pin sources during import

I have a project with several modules, and one module uses the other functions of the modules. So a dependency module has a jar file in compilation dependencies. Therefore, when I try to go to the source, it goes to the .class file from the jar. Instead, I want it to go into the dependent module .java file.

One way is to manually use AttachSources.

Since I have several modules with several dependencies,

  • Is there any way to make it execute during import in any way, say, have sourcePath.txt with the source location in each module.

Project Structure:

ProjectA:

  • ModuleAA (depends on modules)
  • Module AB (module dependent)
  • Moduleac

and many more modules.

+6
source share
1 answer

To access the sources of the modules from your project, instead, to import the jar, you will need to use compile project (':module') .

For example, if I need to build your structure, it will look like this:

ProjectA: (in com.example.projecta)

 dependencies { ... //Other dependencies(appcompat, jar files...) compile project (':moduleaa') //Dependent of moduleAA ... } 

ModuleAA: (in com.example.moduleaa)

 dependencies { ... compile project (':moduleab') //Dependent of moduleAB ... } 

Module AB (in com.example.moduleab)

 dependencies { ... compile project (':moduleac') //Dependent of moduleAC ... } 

ModuleAC (in com.example.moduleac)

 dependencies { ... } 

ProjectA can now access any modules and their dependencies.

To navigate between your project and the source code of your modules, you can use the short key to display the source. You can find the key card under: File > Settings > Keymap > Main menu > View > Jump to source ( or Show source) . (usually control + left click or F12).

EDIT

If you have a module in another project that you need to import and be able to modify, as if it were a module of your current project, you can change your .gradle settings for this current project with

 include ':module' project(':module').projectDir = new File("/<path_to_module>/other_project/module") 

Then the module will appear in your current project.

+3
source

All Articles