Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a dependency to another project properly using gradle?

Hello I am new to gradle and it is a little bit confusing for me. How should I add a dependency in my gradle configuration to have access to B1.java in projectA1? Project B is gradle project and project A is just a folder with another gradle projects.

Here is my structure:

  1. Workspace:
    • ProjectA
      • projectA1
        • ...
        • here I want to have access to B1.java
        • build.gradle
      • projectA2
        • ...
        • build.gradle
    • ProjectB
      • projectB1
        • B1.java
        • ...
        • build.gradle
      • projectB2
        • ...
        • build.gradle
      • build.gradle

I tried to read gradle documentation, but it is not clear for me. Any help appreciated. Thanks!

like image 612
Peters_ Avatar asked Feb 24 '16 15:02

Peters_


People also ask

How do you add a dependency to a project?

To assign dependencies to projectsOn the Project menu, choose Project Dependencies. The Project Dependencies dialog box opens. On the Dependencies tab, select a project from the Project drop-down menu. In the Depends on field, select the check box of any other project that must build before this project does.


1 Answers

You should have a structure like this:

ProjectA
|--projectA1
|----build.gradle
|--projectA2
|----build.gradle
|--settings.gradle
|--build.gradle

ProjectB
|--projectB1
|----build.gradle
|--projectB2
|----build.gradle
|--settings.gradle
|--build.gradle

You can link an external module in your project.

1) In your project projectA/settings.gradle

include ':projectA1',':projectA2',':projectB1' 
project(':projectB1').projectDir = new File("/workspace/projectB/projectB1")

2) Add dependency in build.gradle of projectA1 module

dependencies {
    compile project(':projectB1')
}
like image 112
Gabriele Mariotti Avatar answered Sep 19 '22 13:09

Gabriele Mariotti