Alwaysblue
Alwaysblue

Reputation: 11830

Difference between Settings gradle, property gradle and build gradle

I am new to java and I was going through this article on medium

Here author wrote something like this to explain project file

The settings.gradle file contains a list of your modules and project name. Keep in mind that an Android project can consist of one or several modules, which can each contain their own feature or logic. The gradle.propertiesfile defines your settings and configures a build environment. The gradle, gradlew, and gradlew.bat files are related to Gradle wrapper, so we don’t have to manually install Gradle. build.gradle is a top-level build file. Here we can add configuration options shared by all modules. For example, you can give your files access to repositories for core Android functionalities.

Which I am unable to comprehend. So I googled and stumbled upon this amazing SOF answer

Settings gradle

For settings.gradle I was able to comprehend that

But I didn't got what he meant when he said

mark the directory root of a tree of modules,

And

submodule lookup can be customized

Build gradle

In the build.gradle file of the main module, you can use allprojects {} or subprojects {} to define settings for all other modules.

Wasn't that what settings.gradle was for? to define settings for all included sub-module

Can someone answer my above question? Also, gradle.properties in Android should be used more or less like environment file?

Upvotes: 3

Views: 2479

Answers (1)

Nicolas
Nicolas

Reputation: 7081

mark the directory root of a tree of modules

The folder containing settings.gradle will be considered the root directory of your project. All modules are contained within this directory.

submodule lookup can be customized

I don't really know about this. The only two things I've seen declared in settings.gradle is include and custom dependency resolution rules (you can also put your buildscript {} there apparently).

Maybe it meant that with include you can specify any directory to be marked as a module? For example you can do :app:features:feature1 to declare the app/features/feature1 directory as a module.

There's a documentation page on settings.gradle if you're interested.

In the build.gradle file of the main module, you can use allprojects {} or subprojects {} to define settings for all other modules.

Wasn't that what settings.gradle was for? to define settings for all included sub-module

allprojects and subprojets are just a way to group duplicate code. For example, you declare dependencies in pretty much every module, and dependencies to be resolved from a repository. So in the root project's build.gradle, we usually have:

allprojects {
    repositories {
        jcenter()
        mavenCentral()
        // etc...
    }
}

If you wanted, you could put a repositories block per module build script and the effect would be the same.

Why is this not in settings.gradle? I think because settings.gradle is more about configuring the project structure than the project itself. Also, since settings.gradle is executed first, the modules aren't defined yet so they can't really be configured.

gradle.properties in Android should be used more or less like environment file

Pretty much. People sometimes declare dependency versions there so they aren't repeated in each module. These properties will be available everywhere, even from settings.gradle.

Hope it helps. I wish I had more answers, this was meant to be a comment but it was a little long.

Upvotes: 3

Related Questions