How to include projects in multiproject build from master directory in Gradle?
Asked Answered
C

2

3

Lets have this structure

enter image description here

I am in subproject1 how to write my settings.gradle file to include subproject1 and subproject2 as subprojects of the root Project. My settings.gradle file is in master directory?

I tried:

include 'root:subproject1', 'root:subproject2'

but nothing happened.

From Gradle doc:

If you execute Gradle from within a project that has no settings.gradle file, Gradle does the following:

  • It searches for a settings.gradle in a directory called master which has the same nesting level as the current dir.
  • If no settings.gradle is found, it searches the parent directories for the existence of a settings.gradle file.
  • If no settings.gradle file is found, the build is executed as a single project build.
  • If a settings.gradle file is found, Gradle checks if the current project is part of the multiproject hierarchy defined in the found settings.gradle file. If not, the build is executed as a single project build. Otherwise a multiproject build is executed.
Celinacelinda answered 18/7, 2014 at 14:15 Comment(0)
G
9
includeFlat 'subproject1', 'subproject2'

includeFlat is a short form for include-ing the projects and then setting their projectDirs as appropriate for a flat directory layout.

For more information, see the "Multi-project builds" chapter in the Gradle User Guide, and the sample builds in the full Gradle distribution.

Glow answered 18/7, 2014 at 14:40 Comment(2)
Ok. Now the projects are visible only when current directory is master. When go to subproject1, gradle projects command shows that there are not subprojects. Should there be build.gradle file in the root dir?Celinacelinda
Well, subproject1 doesn't have any subprojects. Try gradle :projects.Glow
C
0

Good project structure.

settings.gradle of the master directory should have the following include statements to have subproject1, subproject2 as a multi-module project.

rootProject.name = 'app-name'

includeFlat 'subproject1'
includeFlat 'subproject2'
  1. There is no need to have settings.gradle inside subproject1, subproject2 modules.
  2. version.gradle and settings.gradle can be saved best under the master module only.
  3. subproject1, subproject2 can have build.gradle with specific dependencies section wrt to their projects. Common dependencies can be stated under build.gradle of master.
  4. It is nice to have "gradle" with wrapper folder under the master, so that the latest version of the Gradle can be downloaded to build multi-module sub-projects. ( e.g: gradlew )
Casaba answered 2/1, 2021 at 20:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.