Gradle defaultConfig vs buildtypes.all vs buildtypes.each

eth*_*han 7 groovy android gradle

I have search Gradle official website and Android Developer official website, but could not find an answer to this.

  1. In the Andoroid build.gradle, what is the difference between defaultConfig, buildtypes.all, and buildtypes.each. They all seems to have a same effect that set build configuration for different build types (release, debug, etc.)

  2. Why might I use one over the other?

    android {
        ...
    
        defaultConfig {
            ...
        }
        buildTypes {
            release {
                ...
            }
        }
        buildTypes.all {
            ...
        }
        buildTypes.each {
            ...
        }
    }
    
    Run Code Online (Sandbox Code Playgroud)