I’m trying to craft a Gradle multiproject build for a situation in which my project layout is already dictated to me. I have something like this:
-->Shared\
---->SharedComponent1\
------>build.gradle
------>src\
...
---->SharedComponent2\
------>build.gradle
...
-->Product1\
---->ProductComponent1\
------>build.gradle
---->ProductComponent2\
------>build.gradle
...
---->build\
------>settings.gradle
My settings.gradle looks like this:
rootProject.name = 'Product1'
rootProject.projectDir = new File( "${ProjectsRoot}" )
include 'Shared:SharedComponent1'
include 'Shared:SharedComponent2'
include 'Product1:ProductComponent1'
include 'Product1:ProductComponent2'
When I run Gradle in the build folder like this:
gradle -PProjectsRoot=c:\my\project\root\dir projects
I get:
:projects
------------------------------------------------------------
Root project
------------------------------------------------------------
Root project 'build'
No sub-projects
To see a list of the tasks of a project, run gradle <project-path>:tasks
For example, try running gradle :tasks
BUILD SUCCESSFUL
i.e. it doesn’t find the projects I’m trying to build.
Is what I’m trying to do possible with Gradle’s multiproject support? Or am I barking up the wrong tree?
A couple of pointers:
projectDirfor all projects, not just the root project. You should use relative paths, e.g.rootProject.projectDir = new File(settingsDir, "../foo")andproject(":sub1").projectDir = new File(rootDir, "bar"). Here,settingsDirrefers to the directory containingsettings.gradle, androotDiris a shorthand forrootProject.projectDir.(root)Project.children. Note thatsettings.gradleandbuild.gradleuse different types to represent a project – ProjectDescriptor and Project, respectively.settings.gradle, or a subdirectory thereof. From a usability perspective, it is therefore best to putsettings.gradleinto the root of the directory hierarchy.For more information, see Settings in the Gradle Build Language Reference, and the Multi-Project Builds chapter in the Gradle User Guide.