Skip to content
/ Grapla Public template

How to graple with Gradle Plugins and conventions: always kept up-to-date

License

Notifications You must be signed in to change notification settings

tamzi/Grapla

Grapla

Build License: MIT Kotlin

Grapla is a modern Android app template showcasing best practices for multi-module architecture with a dedicated design system library. Perfect for jumpstarting your next Android project with convention plugins and a scalable structure.

🎯 Features

  • βœ… Multi-module architecture with clear separation of concerns
  • βœ… Design System (Gruid) - Reusable UI components library
  • βœ… Convention Plugins - Build logic sharing across modules
  • βœ… Jetpack Compose - Modern declarative UI toolkit
  • βœ… Material 3 - Latest Material Design components
  • βœ… Gradle Version Catalogs - Centralized dependency management
  • βœ… Hilt - Dependency injection
  • βœ… Detekt - Static code analysis and formatting
  • βœ… CI/CD - Automated workflows with GitHub Actions

πŸ“¦ Project Structure

Grapla/
β”œβ”€β”€ app/              # Main application module
β”œβ”€β”€ gruid/            # Design system library (Grapla UI Design)
β”œβ”€β”€ gruiddemo/        # Design system showcase module
β”œβ”€β”€ buildLogic/       # Convention plugins for build logic
β”‚   └── convention/   # Shared build configuration
β”œβ”€β”€ data/             # Data layer modules
β”œβ”€β”€ datasources/      # Data source implementations
└── scripts/          # Git hooks and automation scripts

πŸ—οΈ Architecture

Convention Plugins (Build Logic)

Grapla uses convention plugins to share build configuration across modules. This approach:

  • βœ… Reduces build script duplication
  • βœ… Ensures consistency across modules
  • βœ… Makes build logic testable and maintainable
  • βœ… Simplifies module setup

Available Convention Plugins:

  • grapla.android.application - Android app modules
  • grapla.android.library - Android library modules
  • grapla.android.library.compose - Compose library modules
  • grapla.android.application.compose - Compose app modules
  • grapla.hilt - Hilt dependency injection
  • grapla.android.lint - Lint configuration
  • grapla.android.room - Room database setup

See the buildLogic README for more details.

Design System (Gruid)

The Gruid module contains reusable UI components following atomic design principles:

  • Atoms - Basic building blocks (colors, typography)
  • Molecules - Simple component combinations
  • Components - Complex, reusable UI elements
  • Theme - App-wide theming configuration

πŸš€ Getting Started

Prerequisites

  • Android Studio - Latest stable version
  • Java 21 - Required for Gradle and Kotlin compilation
  • Gradle 8.7+ - Project uses Gradle wrapper

Setup

  1. Clone the repository

    git clone https://github.com/tamzi/Grapla.git
    cd Grapla
  2. Set Java 21 in Android Studio

    • Go to: Settings > Build, Execution, Deployment > Build Tools > Gradle
    • Set Gradle JDK to 21
  3. Install Git Hooks ⚑ AUTO-INSTALLED!

    Git hooks are automatically installed during the first Gradle sync.

    Manual installation (if needed):

    ./scripts/install-git-hooks.sh

    Verify installation:

    ./scripts/verify-hooks.sh

    These hooks enforce code quality and commit rules automatically.

  4. Sync Gradle

    ./gradlew sync
  5. Build the project

    ./gradlew build
  6. Run the app

    • Select the app run configuration
    • Choose your device/emulator
    • Click Run ▢️

πŸ§ͺ Testing

# Run all tests
./gradlew test

# Run tests for specific module
./gradlew :app:test
./gradlew :gruid:test

βš™οΈ Common Commands

# Build all modules
./gradlew build

# Build specific module
./gradlew :app:build
./gradlew :gruid:build

# Clean build
./gradlew clean

# Run tests
./gradlew test

# Code quality checks
./gradlew detekt
./gradlew lint

# Auto-format code
./gradlew detekt --auto-correct

# Install app on device
./gradlew installDebug

# View all available tasks
./gradlew tasks

🎨 Design System Usage

To use Gruid components in your modules:

  1. Add dependency in your module's build.gradle.kts:

    dependencies {
        implementation(project(":gruid"))
    }
  2. Use components:

    @Composable
    fun MyScreen() {
        GraplaTheme {
            // Your UI here
        }
    }
  3. Explore the catalog

    • Check out the gruiddemo module for component examples
    • Run the gruiddemo app to see all components in action

πŸ› οΈ Development

Code Style

The project uses Detekt for code analysis and formatting:

# Run code analysis and formatting checks
./gradlew detekt

# Auto-format code (fixes formatting issues)
./gradlew detekt --auto-correct

🎣 Git Hooks - Automated Quality Checks

Git hooks automatically validate your code before commits and pushes, catching issues early.

πŸŽ‰ Automatic Installation

Good news! Git hooks are automatically installed when you first sync the project in Gradle.

No manual setup needed - just clone and build!

Manual Installation (If Needed)

If for some reason hooks aren't auto-installed, run:

./scripts/install-git-hooks.sh

That's it! All hooks are now installed and active.

Verify Installation

./scripts/verify-hooks.sh

Expected output:

βœ… All git hooks are properly installed

What Do The Hooks Do?

Pre-Commit Hook (runs when you commit)

  • βœ… Validates build succeeds
  • βœ… Runs tests
  • βœ… Checks code quality (detekt, lint)
  • βœ… Enforces commit rules (file count, naming, etc.)
  • ⏱️ Takes ~30-60 seconds

Pre-Push Hook (runs when you push)

  • βœ… Validates all commits in push
  • βœ… Ensures no mixed code/doc changes
  • βœ… Runs detekt and tests
  • ⏱️ Takes ~15-30 seconds

Common Hook Scenarios

βœ… Successful commit:

git add MyFile.kt
git commit -m "feat: add new feature"
# Hooks run automatically, checks pass βœ“
# Commit succeeds

❌ Blocked commit (too many files):

git add file1.kt file2.kt file3.kt file4.kt file5.kt file6.kt
git commit -m "feat: big change"
# ❌ VIOLATION: 6 files staged (maximum: 5)
# Fix: Split into smaller commits

πŸ”§ How to fix:

# Split your changes into smaller commits
git reset HEAD~1
git add file1.kt file2.kt
git commit -m "feat: add feature part 1"
git add file3.kt file4.kt
git commit -m "feat: add feature part 2"

Bypassing Hooks (Emergency Only)

In rare emergencies, you can skip hooks:

git commit --no-verify   # Skip pre-commit
git push --no-verify     # Skip pre-push

⚠️ Warning: This is strongly discouraged! Violations will still be caught by:

  • CI/CD checks (slower feedback)
  • Server-side hooks (cannot be bypassed)
  • Code review

Troubleshooting

Hooks not running?

# Check status
./scripts/verify-hooks.sh

# Reinstall if needed
./scripts/install-git-hooks.sh

Hooks too slow?

  • They run build and tests to prevent broken commits
  • This saves time by catching issues before they enter git history
  • Commit less frequently, or push more often (pre-push is faster)

Need more details?

  • Quick guide: docs/quickStartHooks.md
  • Full documentation: scripts/README.md
  • Enforcement strategy: docs/gitHookEnforcement.md

🀝 Contributing

Contributions are welcome! Please read our Contributing Guidelines and Code of Conduct.

Quick Start for Contributors

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes
  4. Run tests: ./gradlew test
  5. Format code: ./gradlew detekt --auto-correct
  6. Commit: git commit -m 'feat(module): add amazing feature'
  7. Push: git push origin feature/amazing-feature
  8. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Inspired by Now in Android best practices
  • Design system patterns from Dashiki
  • Images in samples from Pexels:
    • lilartsy
    • Tirachard Kumtanom
    • Quang Anh Ha Nguyen

πŸ“§ Contact

⭐ If you find this template helpful, consider giving it a star!

About

How to graple with Gradle Plugins and conventions: always kept up-to-date

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published