Gradle submodule require another submodule as dependency nested deeper in other dir

I’m working as intern for a company which has base/common modules on github as open source, and some proprietary modules on their self hosted servers.

They have their own plugin to start building any module, and using gradle as their build system.

I’m frequently given tasks related to migrating a module to newer version, and subsequent ones which depend on the module.

Usually, any proprietary module will have have build.gradle as:


plugins {
    id 'com.company_name.app'
}

company_name {
    title "company_name :: module name"
    description "company_name module"
}

dependencies {
    api "com.company.apps:common-module-1:6.1.0"
    api "com.company.apps:common-module-2:6.1.0"
}

and the folder structure of the submodules is:

base app
├─build.gradle
├─settings.gradle
┊
└─modules
  ├─proprietary module
  │ └─build.gradle
  └─common
    ├─common module 1
    │  └─build.gradle
    │
    ├─common module 2
    │  └─build.gradle
    │
    ├─common module 3
    │  └─build.gradle
    ┊
    └─common module n
       └─build.gradle

The issue I face most commonly is changing the dependencies to use local modules instead of downloading them as external dependencies.

Since, the common modules are already nested one level deeper, and in a different directory, they aren’t directly accessible to the proprietary modules.

The build.gradle of base app has this code block:

dependencies {
  gradle.appModules.each { dir ->
    implementation project(":modules:$dir.name")
  }
}

and settings.gradle has:

def modules = []
file("modules").traverse(type: groovy.io.FileType.DIRECTORIES, maxDepth: 1) { it ->
  if (new File(it, "build.gradle").exists()) {
    modules.add(it)
  }
}

gradle.ext.appModules = modules

modules.each { dir ->
  include "modules:$dir.name"
  project(":modules:$dir.name").projectDir = dir
}

to load the modules dynamically.

The issue arises when I replace the code in build.gradle of proprietary modules from

dependencies {
    api "com.company.apps:common-module-1:6.1.0"
    api "com.company.apps:common-module-2:6.1.0"
}

to

dependencies {
    api project(":modules:common-module-1")
    api project(":modules:common-module-2")
}

it shows error that it can’t find or load the common modules the proprietary module depends on!

The current makeshift way I am using is changing the build.gradle file of base app to

dependencies {
    
  gradle.appModules.each { dir ->
      
      if (dir.name.startsWith('common')) {
          implementation project(":modules:common:$dir.name")
      } else {
          implementation project(":modules:$dir.name")        
      }
  }
}

What can be a better solution, so I won’t have to change the base file each time I clone it to migrate another module or any extra file I can add to repo and git-ignore it to make my work easy ?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật