Есть несколько способов, о которых я могу подумать
1 - Добавить зависимости ко всем подпроектам (в родительском)
subprojects {
dependencies {
implementation 'com.google.guava:guava:23.0'
testImplementation 'junit:junit:4.12'
}
....
}
2 - Добавить зависимости для определенных подпроектов (в родительском)
// this will add dependencies to project a, b, and c
// when You add a new subproject, You have to add it to here also
// If You these need dependencies available in it
configure([project(':a'), project(':b'), project(':c')]) {
dependencies {
implementation 'com.google.guava:guava:23.0'
.....
}
}
3 - Использование метода для добавления зависимостей
//in parent
// define a method to add dependencies
// sub projects who need these dependencies will call this method
def addDependencies(subProject) {
subProject.dependencies.add("implementation", "com.google.guava:guava:23.0")
subProject.dependencies.add("implementation", "org.apache.commons:commons-lang3:3.8.1")
// add others
}
// in child
dependencies {
addDependencies(this)
// You can add other dependencies here If this child has any
}
4 - Определить зависимости в виде списка в родительском
// parent
ext.appDependencies = [
[configuration: "implementation", dependency: "org.apache.commons:commons-lang3:3.8.1"],
[configuration: "implementation", dependency: "com.google.guava:guava:23.0"]
]
// child
dependencies {
rootProject.appDependencies.each {
add(it.configuration, it.dependency)
}
}
Подробное описание этого метода приведено в следующей ссылке, в которой для определения этих зависимостей используется внешний файл.
https://hackernoon.com/android-how-to-add-gradle-dependencies-using-foreach-c4cbcc070458
Вы также можете комбинировать 3. и 4. методы, такие как определение списка с зависимостями, вызов функции, которая выполняет итерацию и добавление зависимостей в этот список.
Я бы использовал первый или второй метод, если смогу. (Также могут быть другие способы достижения этого.)