Reputation: 93
I'm new to gradle, and I'm trying using gradle to build projects in Eclipse with Gradle IDE plugin.(Gradle version 2.3, Gradle IDE version 3.6.3)
I have an example of three Java projects in flat layout with dependency A->B->C. The project A, B and C know nothing about the others except the direct dependency. I need to build each of the projects.
I successfully made B depend on C with settings.gradle file in Project B to include Project C, and the build of B and C was successful.
include ":C"
project(':C').projectDir = new File(settingsDir, '../C')
Then I tried adding dependency A -> B with the same way I had tried with B->C (by adding the settings.gradle file). But this time the build of project A failed with error: cannot find C under /B. The settings.gradle file in project B was not read.
I don't want to add dependency info of C to A to build A, for A should not know about C. I searched and could not get the answer. Is there a way to resolve this kind of transitive project dependency in gradle? Thanks very much.
Upvotes: 0
Views: 160
Reputation: 93
I have solved the problem myself with the studying of gradle DSL document and some groovy. I add the following code in my settings.gradle files to apply settings.gradle of the subproject if it exists.
def applySettings = {
def file = new File(project(it).projectDir, "settings.gradle");
if (file.exists()) {
apply "from" : file.toURI()
}
}
applySettings ':B'
Upvotes: 1