Overview
TechSales uses Gradle with Kotlin DSL for build configuration. The project follows modern Android build practices with centralized dependency management through version catalogs.Project Structure
The Gradle configuration is split across multiple files:build.gradle.kts- Root project configurationapp/build.gradle.kts- Application module configurationsettings.gradle.kts- Project settings and repository configurationgradle/libs.versions.toml- Version catalog for centralized dependency managementgradle.properties- Gradle and Android build properties
Root Build Configuration
The rootbuild.gradle.kts file contains configuration common to all sub-projects:
build.gradle.kts
The
apply false syntax means the plugin is declared but not applied at the root level. It will be applied in the app module.Key Features
Declares plugins using the version catalog (
libs.plugins). This approach centralizes plugin versions in libs.versions.toml.Set to
false in root build file to declare plugins without applying them. Sub-modules can then apply the plugin without specifying versions.Settings Configuration
Thesettings.gradle.kts file configures repository locations and project structure:
settings.gradle.kts
Plugin Management
Defines where Gradle should look for plugins. Order matters - repositories are searched sequentially.
- Google Maven - Filtered to only include Android, Google, and AndroidX packages
- Maven Central - General purpose repository
- Gradle Plugin Portal - Official Gradle plugins
Dependency Resolution
Set to
FAIL_ON_PROJECT_REPOS to enforce centralized repository management. Prevents modules from declaring their own repositories.Project Structure
The name of the root project, displayed in Android Studio and used in various build outputs.
Declares which modules are part of the project. TechSales includes the
:app module.Gradle Properties
Thegradle.properties file contains build-wide configuration:
gradle.properties
Performance Settings
JVM arguments for the Gradle daemon. Allocates 2GB of heap memory and sets UTF-8 encoding.
If you experience out-of-memory errors during builds, increase the
-Xmx value (e.g., -Xmx4096m for 4GB).Android Settings
Enables AndroidX libraries instead of legacy support libraries. Should always be
true for modern projects.Optimizes R class generation. Each library’s R class only contains its own resources, reducing APK size.
Version Catalog
The version catalog (gradle/libs.versions.toml) centralizes dependency versions:
gradle/libs.versions.toml
Benefits of Version Catalogs
- Centralized Version Management - Update versions in one place
- Type-Safe Accessors - Use
libs.appcompatinstead of string literals - IDE Support - Auto-completion and version checking
- Consistency - Ensures all modules use the same versions
Version catalogs are accessed using the
libs prefix in build files: libs.plugins.android.application, libs.appcompat, etc.Adding Custom Repositories
To add a custom repository (e.g., for a private package):settings.gradle.kts
Gradle Wrapper
TechSales uses the Gradle Wrapper to ensure consistent builds across environments:gradlew(Unix/Mac) - Wrapper script for Unix-based systemsgradlew.bat(Windows) - Wrapper script for Windowsgradle/wrapper/gradle-wrapper.properties- Wrapper configuration
Using the Wrapper
Always use
./gradlew instead of gradle to ensure everyone uses the same Gradle version.Common Tasks
Updating Gradle
Viewing Dependencies
Cleaning Build
Best Practices
- Use Version Catalogs - Centralize dependency versions in
libs.versions.toml - Kotlin DSL - Prefer
.ktsfiles for type safety and IDE support - Centralize Repositories - Define all repositories in
settings.gradle.kts - Use Gradle Wrapper - Ensures consistent builds across machines
- Optimize Memory - Adjust
org.gradle.jvmargsbased on your machine’s capacity - Enable Build Cache - Add
org.gradle.caching=truetogradle.propertiesfor faster builds
Related Documentation
- Dependencies Configuration - Managing project dependencies
- Build Types - Debug and release configurations
- Project Structure - Application module structure