Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically attach sources during import

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

One way is to manually do AttachSources.

Since, I have multiple modules with multiple dependencies;

  • Is there a way to get it executed during import by some means, say having a sourcePath.txt with source location under each module.?

Project Structure:

ProjectA :

  • ModuleAA (depends upon ModulesAB)
  • ModuleAB (depends upon ModulesAC)
  • ModuleAC

and many more modules.

like image 797
thepace Avatar asked Sep 11 '15 10:09

thepace


1 Answers

In order to access the modules' sources from your project, instead to import a jar, you will have to use compile project (':module').

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

ProjectA: (under com.example.projecta)

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

ModuleAA: (under com.example.moduleaa)

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

ModuleAB (under com.example.moduleab)

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

ModuleAC (under com.example.moduleac)

dependencies {
    ...
}

Now the ProjectA can access to any modules and their dependencies.

To navigate between your project and the source code of your modules, you can use the short key to show the source. You can find the keymap 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 an other project that you what to import and be able to modify as if it is a module on your current project, you can modify your settings.gradle of 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.

like image 73
xiaomi Avatar answered Oct 21 '22 07:10

xiaomi