overview

  • At the heart of Gradle lies a rich extensible Domain Specific Language (DSL) based on Groovy.
  • Gradle follows your layout not vice versa.
  • And Groovy is our glue that allows you to tell your individual story with the abstractions Gradle (or you) provide.
  • The Gradle Wrapper allows you to execute Gradle builds on machines where Gradle is not installed.

Three Concepts

the build script

Gradle automatically looks for a file called build.gradle in the current directory. This file define the projects and tasks make up the build

projects

Gradle can work with a single or multiple projects per build

Tasks

building block of the build

why groovy

  • like java
  • vs Python, Groovy or RubyGroovy, offers by far the greatest transparency for Java people.

gradle phases

  • init
    • Sets up the environment
    • determine which projects will take part in
  • configuration
    • Constructs and configures the task graph
    • determines which tasks need to run and in which order
  • execution
    • Runs the tasks selected at the end of the configuration phase.

afterEvaluate

  • put its config after other configuration and before execution.
  • So evaluation executes after a the end of configuration and before execution

build script

Everything in Gradle sits on top of two basic concepts: projects and tasks.

  • Every Gradle build is made up of one or more projects.
  • Each project is made up of one or more tasks.

project

  • There is a one-to-one relationship between a Project and a build.gradle file
  • 创建setting实例,根据settings.gradle来决定project的层级关系
  • 执行projects根据广度遍历规则

build.gradle

automatically looks for this file as the build script

plugin

  • bundle additional tasks into Gradle that focus on a specific functionality.
  • modularise and reuse project configuration.

plugin type

  • script plugins
  • binary plugins

Dependency Management Terminology

configuration

  • a named set of dependencies grouped together for a specific goal
  • the scope of a dependency

dependencies

a pointer to another piece of software required to build, test or run a module

Build Variant

The combination of Build Type and Flavor is known as Build Variant.

  • Build Type
    Build Type refers to build and packaging settings like signing configuration for a project.
    • debug
    • release
  • Flavour
    A flavor is used to specify custom features,
    • minimum and target API levels,
    • device and API requirements like layout, drawable
    • and custom code (for example, if production code is slightly different than development code).