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 ?