First, all of this code is available on GitHub at https://github.com/pcclark4/GradleDependencyTest, which may make it easier to follow what I’m about to describe.
I have a unique problem in which a main module loads classes at runtime using reflection if they exist. Project1 contains two modules: Lolol, the main application module that uses reflection to load an instance of a class that implements TestInterface, and LibLib, the module which contains the TestInterface interface.
Using the settings.gradle file in Project2, I manually go up a directory then back down into the Project1 directory in order to define those projects. Therefore, I can open up the settings.gradle file and see Project2 as well as the two modules from Project1. The module Rofl in Project2 is a library module which depends on LibLib from Project1 so I can define a class that extends TestInterface.
If I were to open Project1, I can still build it even without Project2, because it truly doesn’t care if that class is there or not. It will just load it if its available. However, if I open Project2, I need the Lolol module to see Rofl as a dependency when it is built. I do NOT want to manually insert “compile project(’:Rofl’)” into Lolol’s build.gradle file every time I decide to add an extension. Instead, I would prefer if I could programmatically tell Lolol, using Rofl’s build.gradle file, that it needs to build Rofl as a dependency.
I have tried adding this inside of Rofl’s build.gradle:
project(':Lolol').dependencies {
compile project(':Rofl')
}
No success, however.
I hope I’ve worded everything correctly. I greatly appreciate any suggestions! The directory structure is below, but like I said, it might be easier to just view my GitHub project.
├── Project1
│ ├── build.gradle
│ ├── LibLib
│ │ ├── build.gradle
│ │ └── src
│ │
└── main
│ │
├── AndroidManifest.xml
│ │
└── java
│ │
└── com
│ │
└── eowdaoc
│ │
└── liblib
│ │
└── TestInterface.java
│ ├── Lolol
│ │ ├── build.gradle
│ │ └── src
│ │
└── main
│ │
├── AndroidManifest.xml
│ │
└── java
│ │
└── com
│ │
└── eowdaoc
│ │
└── lolol
│ │
└── TestActivity.java
│ └── settings.gradle
├── Project2
│ ├── build.gradle
│ ├── Rofl
│ │ ├── build.gradle
│ │ └── src
│ │
└── main
│ │
├── AndroidManifest.xml
│ │
└── java
│ │
└── com
│ │
└── eowdaoc
│ │
└── rofl
│ │
└── TestClass.java
│ └── settings.gradle