What is the difference between all projects and subprojects

In a multi-project gradle build, can someone tell me what exactly is the difference between the "allprojects" section and the "subprojects"? Only the parent directory? Does anyone use both? If so, do you have general rules that define what is usually set in each of them?

Related question: what is the difference between the two syntaxes (valid for all projects AND subprojects):

subprojects { ... } 

and

 configure(subprojects) { ... } 

When are you one by one?

+59
gradle
Aug 22 2018-12-12T00:
source share
2 answers

In a multi-project gradle build, you have rootProject and subprojects. The combination of both is all projects. RootProject is the beginning of the build. The usual template - rootProject has no code, and subprojects are java projects. In this case, you apply the java plugin only to subprojects:

 subprojects { apply plugin: 'java' } 

This will be equivalent to the maven aggregate pom project, which only builds submodules.

As for the two syntaxes, they do the same thing. The first one just looks better.

+57
Aug 22 '12 at 16:14
source share

Adding to Ryan's answer, the configure method becomes important when you want to configure custom subsets of objects. For example configure([project(":foo"), project(":bar")]) { ... } or configure(tasks.matching { it.name.contains("foo") }) { ... } .

When to use allprojects vs. subprojects depend on the circumstances. Often you will use both. For example, code-related plugins, such as the Java plugin, are usually applied to subprojects because in many builds the root project does not contain any code. On the other hand, Eclipse and IDEA plugins are usually applied to allprojects . If in doubt, see examples and other assemblies and / or experiments. The overall goal is to avoid unnecessary configuration. In this sense, subprojects better than allprojects as long as it gives the expected results.

+30
Aug 22 '12 at 16:32
source share



All Articles