What's the difference between buildscript and allprojects in build.gradle?

后端 未结 2 1308
灰色年华
灰色年华 2020-12-12 12:42

On a multi-project gradle build, can someone tell me what exactly is the difference between the \"allprojects\" section and the \"buildscript\" one? Both have a repos

2条回答
  •  无人及你
    2020-12-12 13:14

    TL;DR: buildscript helps find plugins, allprojects applies to all projects


    https://docs.gradle.org/current/userguide/userguide_single.html#applyPluginBuildscript says

    Binary plugins that have been published as external jar files can be added to a project by adding the plugin to the build script classpath and then applying the plugin.

    So you need buildscript for gradle to find the plugins, as

    Gradle at its core intentionally provides very little for real world automation. All of the useful features, like the ability to compile Java code, are added by plugins. Plugins add new tasks (e.g. JavaCompile), domain objects (e.g. SourceSet), conventions (e.g. Java source is located at src/main/java) as well as extending core objects and objects from other plugins.

    Concerning allprojects:

    The Project API provides a property allprojects which returns a list with the current project and all its subprojects underneath it. If you call allprojects with a closure, the statements of the closure are delegated to the projects associated with allprojects.

提交回复
热议问题