Skip to content
/ Gradle Public template

A comprehensive Gradle boilerplate template with modern development practices, testing frameworks, code quality tools, and CI/CD integration for Java/Kotlin projects.

License

Notifications You must be signed in to change notification settings

emgeiger/Gradle

Repository files navigation

Gradle Boilerplate Project

A comprehensive Gradle boilerplate template for Java/Kotlin projects with modern development practices, testing, and CI/CD integration.

πŸš€ Features

  • Modern Gradle Setup: Kotlin DSL configuration with Gradle 8.11.1
  • Java 17+ Support: Compatible with Java 17 and 21
  • Kotlin Integration: Ready for mixed Java/Kotlin projects
  • Testing Framework: JUnit 5, AssertJ, and Mockito
  • Code Quality: Checkstyle, PMD, SpotBugs integration
  • Code Coverage: JaCoCo for test coverage reporting
  • CI/CD Pipeline: GitHub Actions workflow
  • Multi-platform Testing: Tests on Ubuntu, Windows, and macOS
  • Dependency Management: Centralized dependency configuration
  • Documentation: Comprehensive README and inline documentation

πŸ“ Project Structure

β”œβ”€β”€ .github/
β”‚   β”œβ”€β”€ workflows/
β”‚   β”‚   └── ci.yml                    # GitHub Actions CI/CD pipeline
β”‚   └── copilot-instructions.md       # GitHub Copilot configuration
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ checkstyle/
β”‚   β”‚   └── checkstyle.xml           # Checkstyle configuration
β”‚   β”œβ”€β”€ pmd/
β”‚   β”‚   └── ruleset.xml              # PMD rules
β”‚   └── spotbugs/
β”‚       └── exclude.xml              # SpotBugs exclusions
β”œβ”€β”€ gradle/
β”‚   └── wrapper/                     # Gradle wrapper files
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main/java/                   # Main source code
β”‚   └── test/java/                   # Test source code
β”œβ”€β”€ build.gradle.kts                 # Gradle build script
β”œβ”€β”€ gradlew                          # Gradle wrapper (Unix)
β”œβ”€β”€ gradlew.bat                      # Gradle wrapper (Windows)
└── settings.gradle.kts              # Gradle settings

πŸ› οΈ Prerequisites

  • Java 17 or higher
  • Git

οΏ½ Corporate Network Setup

Important: If you're working in a corporate environment with SSL inspection or proxies, you may encounter SSL certificate errors when first running Gradle. This is because the Gradle wrapper needs to download Gradle itself before it can read the gradle.properties configuration.

Quick Fix for Corporate Networks

  1. Run the setup script:

    # PowerShell (recommended)
    .\setup-corporate-network.ps1
    
    # Or Command Prompt
    setup-corporate-network.bat
  2. Manual alternative: Download Gradle manually from https://services.gradle.org/distributions/gradle-8.11.1-all.zip and extract to the project directory.

  3. Complete guide: See CORPORATE-NETWORK-GUIDE.md for detailed troubleshooting.

Configuration Files

  • gradle.properties: Pre-configured with corporate network settings
  • setup-corporate-network.ps1: Automated setup script
  • CORPORATE-NETWORK-GUIDE.md: Comprehensive troubleshooting guide

🚦 Quick Start

For Standard Networks

  1. Use this template: Click "Use this template" button on GitHub or clone the repository
  2. Update project details: Modify package names, project name, and description
  3. Run tests: ./gradlew test
  4. Build project: ./gradlew build

For Corporate Networks

  1. Follow corporate setup: See section above for SSL/proxy configuration
  2. Run setup script: .\setup-corporate-network.ps1
  3. Update project details: Same as standard networks
  4. Build and test: Use provided scripts or manual Gradle download

πŸ“ Available Gradle Tasks

Build Tasks

  • ./gradlew build - Build the entire project
  • ./gradlew cleanBuild - Clean and build the project
  • ./gradlew run - Run the main application

Testing Tasks

  • ./gradlew test - Run all tests
  • ./gradlew jacocoTestReport - Generate test coverage report
  • ./gradlew jacocoTestCoverageVerification - Verify coverage meets threshold

Code Quality Tasks

  • ./gradlew codeQuality - Run all code quality checks
  • ./gradlew checkstyleMain - Run Checkstyle on main sources
  • ./gradlew pmdMain - Run PMD on main sources
  • ./gradlew spotbugsMain - Run SpotBugs on main sources

πŸ§ͺ Testing

The project uses JUnit 5 as the testing framework with:

  • AssertJ for fluent assertions
  • Mockito for mocking dependencies
  • Test coverage reporting with JaCoCo

Example test structure:

@Test
@DisplayName("Should return greeting message")
void shouldReturnGreetingMessage() {
    // Given
    App app = new App();
    
    // When
    String greeting = app.getGreeting();
    
    // Then
    assertThat(greeting).isEqualTo("Hello World!");
}

πŸ” Code Quality

The project includes comprehensive code quality tools:

  • Checkstyle: Enforces Google Java Style Guide
  • PMD: Static analysis for potential issues
  • SpotBugs: Bug pattern detection
  • JaCoCo: Code coverage analysis (80% minimum coverage)

Run all quality checks:

./gradlew codeQuality

πŸ”„ CI/CD Pipeline

The GitHub Actions workflow includes:

  • Multi-platform testing (Ubuntu, Windows, macOS)
  • Multi-Java version testing (Java 17, 21)
  • Code quality checks
  • Test coverage reporting
  • Dependency vulnerability scanning
  • Build artifact generation

πŸ“¦ Dependencies

Key dependencies included:

  • Testing: JUnit 5, AssertJ, Mockito
  • Logging: SLF4J with Logback
  • Utilities: Apache Commons Lang, Google Guava
  • Kotlin: Standard library (for mixed projects)

πŸ”§ Customization

Adding Dependencies

Add new dependencies in build.gradle.kts:

dependencies {
    implementation("group:artifact:version")
    testImplementation("test-group:test-artifact:version")
}

Modifying Package Structure

  1. Update package names in build.gradle.kts
  2. Move source files to new package structure
  3. Update imports and references

Configuring Code Quality

  • Checkstyle: Edit config/checkstyle/checkstyle.xml
  • PMD: Edit config/pmd/ruleset.xml
  • SpotBugs: Edit config/spotbugs/exclude.xml

πŸ“‹ Template Usage Guide

Files to Keep (Template Infrastructure)

Keep these files unchanged - they provide the template's core functionality:

πŸ“ Configuration & Build
β”œβ”€β”€ build.gradle.kts                 βœ… Keep (modify project details only)
β”œβ”€β”€ settings.gradle.kts              βœ… Keep (update project name)
β”œβ”€β”€ gradle.properties                βœ… Keep (corporate network settings)
β”œβ”€β”€ gradlew / gradlew.bat            βœ… Keep (Gradle wrapper)
β”œβ”€β”€ gradlew-corporate.*              βœ… Keep (corporate network scripts)
└── gradle/wrapper/                  βœ… Keep (Gradle wrapper files)

πŸ“ Code Quality & CI/CD
β”œβ”€β”€ .github/workflows/ci.yml         βœ… Keep (CI/CD pipeline)
β”œβ”€β”€ .github/copilot-instructions.md  βœ… Keep (GitHub Copilot config)
β”œβ”€β”€ config/checkstyle/               βœ… Keep (code quality rules)
β”œβ”€β”€ config/pmd/                      βœ… Keep (static analysis)
β”œβ”€β”€ config/spotbugs/                 βœ… Keep (bug detection)
└── .gitignore                       βœ… Keep (Git ignore rules)

πŸ“ Documentation
β”œβ”€β”€ CORPORATE-NETWORK-GUIDE.md       βœ… Keep (troubleshooting guide)
β”œβ”€β”€ SETUP.md                         βœ… Keep (setup instructions)
β”œβ”€β”€ setup-corporate-network.*        βœ… Keep (network setup scripts)
└── LICENSE                          βœ… Keep (or update for your license)

Files to Customize (Your Project Content)

Modify these files to match your specific project:

πŸ“ Source Code - CUSTOMIZE
β”œβ”€β”€ src/main/java/com/example/gradle/
β”‚   └── App.java                     πŸ”„ Replace with your main class
β”œβ”€β”€ src/test/java/com/example/gradle/
β”‚   └── AppTest.java                 πŸ”„ Replace with your tests
└── src/main/resources/
    └── logback.xml                  πŸ”„ Keep (modify logging config if needed)

πŸ“ Documentation - CUSTOMIZE
β”œβ”€β”€ README.md                        πŸ”„ Update for your project
└── .github/template-repository.json πŸ”„ Update template metadata

Files to Remove (Template-Specific)

Delete these files after creating your project from the template:

πŸ“ Template Cleanup - REMOVE
└── .github/template-cleanup/
    └── README.md                    ❌ Remove (template instructions only)

Template Checklist

When using this template:

Step 1: Project Configuration

  • Update project name in settings.gradle.kts
  • Modify build.gradle.kts application details:
    • Change application.mainClass from "com.example.gradle.App"
    • Update group name from "com.example"
  • Update repository name and description in this README

Step 2: Source Code

  • Replace src/main/java/com/example/gradle/ with your package structure
  • Create your main application class (replace App.java)
  • Replace example tests with your actual tests
  • Update package imports throughout the codebase

Step 3: Documentation

  • Customize this README for your project
  • Update SETUP.md if you have specific setup requirements
  • Modify .github/template-repository.json if creating another template
  • Update author information and license if needed

Step 4: Template Cleanup

  • Delete .github/template-cleanup/ directory
  • Remove template-specific sections from README
  • Commit your customized project

Step 5: Corporate Network (if applicable)

  • Test corporate network setup scripts work in your environment
  • Verify gradle.properties settings match your network requirements
  • Update CORPORATE-NETWORK-GUIDE.md with environment-specific details

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests and quality checks
  5. Submit a pull request

πŸ“„ License

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

πŸ”— Related Resources

About

A comprehensive Gradle boilerplate template with modern development practices, testing frameworks, code quality tools, and CI/CD integration for Java/Kotlin projects.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors