gradle - How to let subprojects choose their own repository configurations in a multi-project build? -
i'm new using build tools , working on multi-project environments in general i'll try explain best can.
structure
this directory structure. (there's more modules tried keep simple purpose of question)
project vcs repo root +---project a/ | build.gradle | settings.gradle | +---project b/ | build.gradle | +---project c/ | | build.gradle | \---libs/ | +---project d/ | build.gradle | settings.gradle | +---shared libs/ | \---build.gradle project depedencies:
adepends onb,c.ddepends onb,a.
each project can dependency 1 of 3 places:
- mavencentral
- a
libsdirectory own root directory. (thelibsdir underproject cproject cuse) shared libsdirectory in project's parent directory.
however libs folders contents not guaranteed in format, (it not dir jars, there might sub dirs , such)
goal
i want each project buildable project's root directory, , not want keep redundant copy of repositories/dependencies of child project in parent project build. should have provide locations , possibly version numbers of child projects in parent's build file.
my attempt
in c/build.gradle:
apply plugin: 'java' repositories { mavencentral() def mylibsdir = 'libs' flatdir name: 'foo', dirs: "$mylibsdir/foo/4.20" //and similar thing shared libs if needed. } dependencies { // atrifacts can mavencentral or 'c/libs/foo/4.20' } this works fine project c, tasks work expected.
then when setting a: settings.gradle:
includeflat 'project b', 'project c' build.gradle:
repositories { mavencentral() def sharedlibsdir = '../shared libs' flatdir name: 'blazer', dirs: "$sharedlibsdir/blz/pls/13.37" } dependencies { //non-subproject dependencies compile project('project b') compile project('project c') } this almost works. problem that, unlike dependencies, each sub project's repositories {} ignored , parent's used instead. if c depends on in c/libs i'd have include in a/build.gradle 's repositories{}
my guess use this , depend on subproject's artifact(s) directly. idk why method seems harder maintain.
this answer late, thought i'd post else runs problem (as did). in subproject's build.gradle, instead of writing:
repositories { ... } you can write:
[rootproject, this].each { it.repositories { ... } } this copies repository block both current subproject, , whatever project acting root. root project no longer needs know repositories dependents need, should make more maintainable.
Comments
Post a Comment