You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/tutorials/gradle/gradle-essentials.md
+29-7Lines changed: 29 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -714,21 +714,21 @@ However, the include method allows level 1 subproject names to omit the colon.
714
714
So, the include call can be rewritten as follows: `include 'repository', 'services', 'web-app'`
715
715
- The projects task lists all the projects available in a Gradle build: `gradle projects`
716
716
- We can find more information on Settings at the Settings DSL documentation https://docs.gradle.org/current/dsl/org.gradle.api.initialization.Settings.html
717
-
- For a multiproject build, we can call tasks on any nested project using the gradle <project-path>:<task-name> syntax
718
-
or by going into the subproject directory and executing gradle <task-name>.
717
+
- For a multiproject build, we can call tasks on any nested project using the gradle <project-path>:<task-name> syntax
718
+
or by going into the subproject directory and executing gradle <task-name>.
719
719
720
720
### Organizing build logic in multiproject builds
721
-
- Gradle gives us the flexibility to create one build file for all projects or individual build file per project; you can also mix and match.
721
+
- Gradle gives us the flexibility to create one build file for all projects or individual build file per project; you can also mix and match.
722
722
- Gradle DSL provides a first-class support for declaring common build elements across all projects.
723
723
- The allprojects method takes a closure and executes it on the project (object) of the build file and all the subprojects of the current project.
724
-
- We can even apply plugins, declare repositories and dependencies, and so on. So, in essence, we can write any build logic
724
+
- We can even apply plugins, declare repositories and dependencies, and so on. So, in essence, we can write any build logic
725
725
that is common to all projects and then it will be applied to all projects.
726
726
727
727
```
728
728
allprojects {
729
729
task whoami << {println "I am ${project.name}"}
730
730
}
731
-
// or
731
+
// or
732
732
allprojects {
733
733
task("describe${project.name.capitalize()}") << {
734
734
println project.name
@@ -737,13 +737,35 @@ allprojects {
737
737
```
738
738
739
739
### Applying build logic to subprojects
740
-
- the subprojects method applies some build logic only on subprojects without affecting the parent project.
741
-
-
740
+
- the subprojects method applies some build logic only on subprojects without affecting the parent project.
741
+
-
742
742
743
743
```
744
744
subprojects {
745
745
apply plugin: 'java'
746
746
}
747
747
```
748
748
749
+
- Check the output of `gradle -q tasks --all` in this case.
750
+
- The tasks added by the `java` plugin will only be available on subprojects, whereas tasks such
751
+
as help tasks will be available on all projects.
752
+
753
+
### Dependency on subprojects
754
+
- Add dependency declaration in the root project's build.gradle.
755
+
756
+
```
757
+
project(':services') {
758
+
dependencies {
759
+
compile project(':repository')
760
+
}
761
+
}
762
+
```
763
+
764
+
- Add dependency declaration in the child project's build.gradle.
0 commit comments