### Full Example: CLI Configuration Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/exclude-classes.md A comprehensive example demonstrating global exclusions and minimum coverage via CLI arguments. ```bash java -jar delta-coverage-cli.jar \ --diff-file changes.diff \ --engine JACOCO \ --coverage-binary build/jacoco/test.exec \ --classes build/classes/java/main \ --sources src/main/java \ --exclude '**/generated/**/*.*' \ --exclude '**/*$$*.class' \ --exclude '**/BuildConfig.class' \ --min-coverage 0.9 \ --fail-on-violation \ --console ``` -------------------------------- ### README Example with Badges Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/recipes/coverage-badges.md An example of how to include build and coverage badges in a project's README file using markdown. ```markdown # My Project ![Build](https://github.com/owner/repo/actions/workflows/build.yml/badge.svg) ![Coverage](https://img.shields.io/endpoint?url=...) ## Description ... ``` -------------------------------- ### Full Example: Kotlin DSL Configuration Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/exclude-classes.md A comprehensive example demonstrating global exclusions, view-specific exclusions, and view-specific inclusions in Kotlin DSL. ```kotlin configure { diffSource.git.compareWith("refs/remotes/origin/main") // Global exclusions excludeClasses.value( listOf( "**/generated/**/*.*", ``` ```kotlin "**/*$$*.class", ``` ```kotlin "**/BuildConfig.class" ) ) reportViews { val test by getting { // Additional exclusions for this view excludeClasses.value( listOf("**/test/fixtures/**/*.*") ) violationRules.failIfCoverageLessThan(0.9) } val integrationTest by getting { // Only analyze API classes includeClasses.value( listOf("**/api/**/*.class") ) } } } ``` -------------------------------- ### Full Example: Groovy DSL Configuration Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/exclude-classes.md A comprehensive example demonstrating global exclusions, view-specific exclusions, and view-specific inclusions in Groovy DSL. ```groovy deltaCoverageReport { diffSource.git.compareWith('refs/remotes/origin/main') excludeClasses = [ '**/generated/**/*.*', '**/*$$*.class', '**/BuildConfig.class' ] reportViews { test { excludeClasses = ['**/test/fixtures/**/*.*'] violationRules.failIfCoverageLessThan(0.9) } integrationTest { includeClasses = ['**/api/**/*.class'] } } } ``` -------------------------------- ### Full Delta Coverage Configuration Example Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/guides/testing-pyramid.md A comprehensive configuration example demonstrating how to set up diff sources, enable HTML and Markdown reports, and define detailed violation rules for unit, integration, E2E, and aggregated views. ```kotlin configure { diffSource.git.compareWith("refs/remotes/origin/main") reports { html.set(true) markdown.set(true) } reportViews { val test by getting { violationRules { failIfCoverageLessThan(0.9) } } val integrationTest by getting { violationRules { rule(CoverageEntity.LINE) { minCoverageRatio.set(0.7) } rule(CoverageEntity.BRANCH) { minCoverageRatio.set(0.6) entityCountThreshold.set(5) } } } val e2eTest by getting { violationRules { failOnViolation.set(false) // Don't fail, just report all { minCoverageRatio.set(0.5) } } } val aggregated by getting { violationRules.failIfCoverageLessThan(0.8) } } } ``` -------------------------------- ### Quick Start: Run Delta Coverage Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/delta-coverage-cli/README.md Execute the Delta Coverage CLI to perform a delta coverage analysis. This example first generates a diff file and then runs the Java JAR with specified coverage engine, diff file, coverage binary, class directories, source directories, and reporting options. ```bash # Generate diff file git diff origin/main...HEAD > changes.diff # Run delta coverage java -jar delta-coverage-cli.jar \ --engine JACOCO \ --diff-file changes.diff \ --coverage-binary build/jacoco/test.exec \ --classes build/classes/java/main \ --sources src/main/java \ --html --console ``` -------------------------------- ### Local Development Commands Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/adr/landing-page-adr.md Provides commands for installing dependencies, serving the documentation locally, and building the documentation site. Assumes Python and pip are installed. ```bash # Install pip install mkdocs-material # Serve locally mkdocs serve # Build mkdocs build ``` -------------------------------- ### Local Development Report Setup Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/reports.md Configure console and HTML reports for local development. This setup provides immediate feedback during development cycles. ```kotlin reports { console.set(true) html.set(true) } ``` ```groovy reports { console = true html = true } ``` ```bash java -jar delta-coverage-cli.jar --console --html ... ``` -------------------------------- ### Delta Coverage Output Example Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/adr/content-plan.md Example of the output displayed after running the deltaCoverage task, showing key coverage metrics. ```text > Task :deltaCoverage Delta Coverage Report ───────────────────── Changed lines: 14 Covered: 12 Delta coverage: 85% ✓ BUILD SUCCESSFUL ``` -------------------------------- ### Azure DevOps CI/CD Example Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/delta-coverage-cli/README.md Sets up Delta Coverage CLI within an Azure DevOps pipeline. It installs Java, builds the project, generates a diff, downloads and executes the CLI for coverage analysis, and publishes the artifact. The `--fail-on-violation` flag is used for build failure on coverage breaches. ```yaml trigger: - main pool: vmImage: 'ubuntu-latest steps: - task: JavaToolInstaller@0 inputs: versionSpec: '17' jdkArchitectureOption: 'x64' jdkSourceOption: 'PreInstalled' - script: ./gradlew build displayName: 'Build and test' - script: git diff origin/main...HEAD > changes.diff displayName: 'Generate diff' - script: | curl -L -o delta-coverage-cli.jar \ https://repo1.maven.org/maven2/io/github/gw-kit/delta-coverage-cli/3.6.0/delta-coverage-cli-3.6.0.jar java -jar delta-coverage-cli.jar \ --engine JACOCO \ --diff-file changes.diff \ --coverage-binary '$(Build.SourcesDirectory)/build/**/jacoco/*.exec' \ --classes '$(Build.SourcesDirectory)/build/classes/**/main' \ --sources $(Build.SourcesDirectory)/src/main/java \ --report-dir $(Build.ArtifactStagingDirectory)/delta-coverage \ --html --console \ --fail-on-violation displayName: 'Run Delta Coverage' - task: PublishBuildArtifacts@1 condition: always() inputs: pathToPublish: '$(Build.ArtifactStagingDirectory)/delta-coverage' artifactName: 'delta-coverage-report' ``` -------------------------------- ### Verify Plugin Installation (Kotlin DSL) Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/getting-started/installation.md Run this command to verify the Delta Coverage plugin is installed and tasks are registered. Look for 'deltaCoverage' in the task list. ```bash ./gradlew tasks --group="verification" ``` -------------------------------- ### Verify CLI Installation Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/getting-started/installation.md Run this command to verify the CLI JAR is working correctly. Usage information should be printed to the console. ```bash java -jar delta-coverage-cli.jar --help ``` -------------------------------- ### Example Passing Build Output Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/violation-rules.md This output indicates a successful build where no coverage violations were found. ```text > Task :deltaCoverage Fail on violations: true. Found violations: 0. ``` -------------------------------- ### Delta Coverage Local Feedback Example Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/comparison/vs-sonarqube.md Example output from Delta Coverage showing coverage statistics for a specific class after a local run. The results are available in seconds. ```text +----------------------+----------+----------+--------+ | [test] Delta Coverage Stats | +----------------------+----------+----------+--------+ | Class | Lines | Branches | Instr. | +----------------------+----------+----------+--------| | com.example.Feature | 92% | 85% | 90% | +----------------------+----------+----------+--------+ BUILD SUCCESSFUL in 12s ``` -------------------------------- ### Quick Setup: Enforce 90% Coverage (CLI) Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/violation-rules.md Use this command to enforce a 90% minimum coverage for all metrics via the CLI. Requires specifying diff file, coverage binary, classes, and sources. ```bash java -jar delta-coverage-cli.jar \ --min-coverage 0.9 \ --fail-on-violation \ --diff-file changes.diff \ --engine JACOCO \ --coverage-binary build/jacoco/test.exec \ --classes build/classes/java/main \ --sources src/main/java \ --console ``` -------------------------------- ### Quick Setup: Enforce 90% Coverage (Groovy DSL) Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/violation-rules.md Use this to enforce a 90% minimum coverage for all metrics (lines, branches, instructions) in Groovy DSL. Fails the build if the threshold is not met. ```groovy deltaCoverageReport { reportViews { test { violationRules.failIfCoverageLessThan(0.9) } } } ``` -------------------------------- ### Example Module Versions Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/CONTRIBUTING.md Module versions are indicated by tags prefixed with the module name. This format is used for tracking specific releases of each component. ```text delta-coverage/3.2.0 offlins/1.1.0 cover-jet/1.0.3 sampling/0.1.0 ``` -------------------------------- ### Display Per-View Badges in README Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/recipes/coverage-badges.md Markdown examples for displaying the generated per-view coverage badges (unit and integration tests) directly in the README file. ```markdown ![Unit Tests](/.badges/unit-coverage.svg) ![Integration Tests](/.badges/integration-coverage.svg) ``` -------------------------------- ### Quick Setup: Enforce 90% Coverage (Kotlin DSL) Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/violation-rules.md Use this to enforce a 90% minimum coverage for all metrics (lines, branches, instructions) in Kotlin DSL. Fails the build if the threshold is not met. ```kotlin configure { reportViews { val test by getting { violationRules.failIfCoverageLessThan(0.9) } } } ``` -------------------------------- ### GitLab CI/CD Example Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/delta-coverage-cli/README.md Demonstrates integrating Delta Coverage CLI into a GitLab CI pipeline. This script builds the project, creates a diff file, downloads the CLI, and runs coverage analysis with failure on violation. Coverage reports are then archived as artifacts. ```yaml delta-coverage: stage: test image: eclipse-temurin:17-jdk script: - ./gradlew build - git diff origin/main...HEAD > changes.diff - | curl -L -o delta-coverage-cli.jar \ https://repo1.maven.org/maven2/io/github/gw-kit/delta-coverage-cli/3.6.0/delta-coverage-cli-3.6.0.jar - | java -jar delta-coverage-cli.jar \ --engine JACOCO \ --diff-file changes.diff \ --coverage-binary 'build/**/jacoco/*.exec' \ --classes 'build/classes/**/main' \ --sources src/main/java \ --html --console \ --min-coverage 0.8 \ --fail-on-violation artifacts: when: always paths: - build/reports/delta-coverage expire_in: 1 week ``` -------------------------------- ### View-Specific Coverage Binary Files Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/report-views.md Configure specific coverage binary files for a custom view. This example sets coverage files for a view named 'custom'. ```kotlin view("custom") { coverageBinaryFiles = files( "build/jacoco/test.exec", "build/jacoco/integrationTest.exec" ) } ``` -------------------------------- ### Example Failing Build Output Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/violation-rules.md This output shows a build failure due to coverage violations. It details the violated rules and the expected vs. actual coverage ratios. ```text > Task :deltaCoverage FAILED Fail on violations: true. Found violations: 2. FAILURE: Build failed with an exception. > java.lang.Exception: Rule violated for bundle test: instructions covered ratio is 0.5, but expected minimum is 0.9 [test] Rule violated for bundle test: lines covered ratio is 0.0, but expected minimum is 0.9 ``` -------------------------------- ### GitHub Actions CI/CD Example Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/delta-coverage-cli/README.md Integrates Delta Coverage CLI into a GitHub Actions workflow. Ensures Java is set up, builds the project, generates a diff, downloads the CLI, runs coverage analysis, and uploads the report. Use `--fail-on-violation` to fail the build on coverage issues. ```yaml jobs: coverage: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set up JDK uses: actions/setup-java@v4 with: java-version: '17' distribution: 'temurin' - name: Build and test run: ./gradlew build - name: Generate diff run: git diff origin/${{ github.base_ref }}...HEAD > changes.diff - name: Download Delta Coverage CLI run: | curl -L -o delta-coverage-cli.jar \ https://repo1.maven.org/maven2/io/github/gw-kit/delta-coverage-cli/3.6.0/delta-coverage-cli-3.6.0.jar - name: Run Delta Coverage run: | java -jar delta-coverage-cli.jar \ --engine JACOCO \ --diff-file changes.diff \ --coverage-binary 'build/**/jacoco/*.exec' \ --classes 'build/classes/**/main' \ --sources src/main/java \ --html --console \ --min-coverage 0.8 \ --fail-on-violation - name: Upload coverage report uses: actions/upload-artifact@v4 if: always() with: name: delta-coverage-report path: build/reports/delta-coverage ``` -------------------------------- ### Create Custom Report View Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/report-views.md Define a new custom report view with specific configurations. This example creates a view named 'myView'. ```kotlin reportViews { val myView by creating { // Configuration } } ``` -------------------------------- ### Run Specific View Task Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/report-views.md Execute a Gradle task for a specific report view. This example runs the 'deltaCoverageTest' task. ```bash ./gradlew deltaCoverageTest ``` -------------------------------- ### Manual CoverJet Plugin Setup Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/guides/kotlin-projects.md Manually apply the CoverJet plugin and disable auto-apply in Delta Coverage configuration when custom CoverJet settings are needed. ```kotlin // build.gradle.kts plugins { id("io.github.gw-kit.cover-jet") version "1.0.0" } configure { coverage { engine = CoverageEngine.INTELLIJ autoApplyPlugin = false // Don't auto-apply, we did it manually } } ``` -------------------------------- ### List GPG Keys and Get Key ID Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/signing.md List your GPG keys to find the short key ID required for subsequent commands and configuration. ```bash gpg --list-keys --keyid-format short ``` -------------------------------- ### CI Pipeline Report Configuration Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/reports.md Configure console, HTML, Markdown, and XML reports for CI pipelines. This setup is comprehensive, providing visual reports, PR comments, and data for coverage tools. ```kotlin reports { console.set(true) html.set(true) markdown.set(true) // For PR comments xml.set(true) // For coverage tools } ``` ```groovy reports { console = true html = true markdown = true // For PR comments xml = true // For coverage tools } ``` ```bash java -jar delta-coverage-cli.jar \ --console --html --markdown --xml ... ``` -------------------------------- ### Download Delta Coverage CLI JAR Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/getting-started/installation.md Download the CLI JAR from Maven Central or GitHub Releases. This is a standalone JAR with no installation side effects. ```bash curl -L -o delta-coverage-cli.jar \ https://repo1.maven.org/maven2/io/github/gw-kit/delta-coverage-cli/3.6.0/delta-coverage-cli-3.6.0.jar ``` -------------------------------- ### Example HTML Report Layout Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/adr/test-to-code-mapping-adr.md Illustrates the structure and content of the generated HTML report for test-to-code mapping analysis. It includes summary statistics, hot methods, and file-specific line annotations. ```text ┌─────────────────────────────────────────────────────────────┐ │ Test Mapping Report Generated: ... │ ├─────────────────────────────────────────────────────────────┤ │ Summary: │ │ Changed files: 5 │ │ Changed methods: 12 │ │ Covered by tests: 10 (83%) │ │ Coverage gaps: 2 methods │ ├─────────────────────────────────────────────────────────────┤ │ Hot Methods (by hit count) [Toggle View] │ │ ─────────────────────────────────────────────────────────── │ │ 1. Validator.validate() 4521 hits 23 tests ⚠️ │ │ 2. StringUtils.trim() 3200 hits 45 tests │ │ 3. Calculator.add() 890 hits 15 tests │ ├─────────────────────────────────────────────────────────────┤ │ Calculator.java │ │ ─────────────────────────────────────────────────────────── │ │ 45 │ + public int multiply(int a, int b) { 365 hits │ │ │ ├─ CalculatorTest.shouldMultiply (d:1, h:342) │ │ │ └─ OrderServiceTest.calcTotal (d:3, h:23) │ │ 46 │ + return a * b; │ │ │ │ │ 60 │ + private int validate(int x) { ⚠️ NO TESTS │ │ 61 │ + return x > 0 ? x : 0; 0 hits │ │ 62 │ + } │ └─────────────────────────────────────────────────────────────┘ Legend: d = depth, h = hits ``` -------------------------------- ### Build Project Locally Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/CONTRIBUTING.md Clone the repository, navigate to the project directory, and build the project using Gradle. Ensure this command passes before pushing any changes. ```bash git clone https://github.com/gw-kit/delta-coverage-plugin.git cd delta-coverage-plugin ./gradlew build ``` -------------------------------- ### Exclude a Package Pattern Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/exclude-classes.md Example of excluding all classes within a specific package and its subpackages. ```kotlin "**/com/example/generated/**/*.*" ``` -------------------------------- ### Exclude a Specific Class Pattern Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/exclude-classes.md Example of excluding a specific class using a glob pattern. ```kotlin "*/com/example/ExcludeMe.class" ``` -------------------------------- ### Disable a Report View Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/report-views.md Disable an existing report view to skip its report generation. This example disables the 'integrationTest' view. ```kotlin reportViews { val integrationTest by getting { enabled.set(false) } } ``` -------------------------------- ### Configure All Entities at Once (CLI) Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/violation-rules.md Use the `--min-coverage` flag to set a single minimum coverage threshold for all entities via the CLI. ```bash java -jar delta-coverage-cli.jar --min-coverage 0.8 ... ``` -------------------------------- ### Configure Per-Entity Rules (CLI) Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/violation-rules.md The CLI supports a single `--min-coverage` threshold applied to all entities. For per-entity thresholds, a configuration file is required. ```bash java -jar delta-coverage-cli.jar --min-coverage 0.8 --fail-on-violation ... ``` -------------------------------- ### View-Specific Violation Rules Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/report-views.md Configure different violation rules for different views. This example sets distinct coverage thresholds for 'unitTests' and 'integrationTests' views. ```kotlin view("unitTests") { violationRules { failIfCoverageLessThan(0.9) } } view("integrationTests") { violationRules { failIfCoverageLessThan(0.7) // Different threshold } } ``` -------------------------------- ### Enable Diff Explanation Report Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/diff-sources.md Run this Gradle command to generate an explanation report for diff issues. This report details how the plugin interprets the diff and can help debug empty coverage reports. ```bash ./gradlew deltaCoverage -PexplainOnly ``` -------------------------------- ### v3 Delta Coverage Configuration Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/migration-guilde-v3.md Configuration for Delta Coverage Plugin v3. This version uses a `reportViews` block for coverage and violation rule setup. ```kotlin configure { // ... reportViews { val aggregated by getting { coverageBinaryFiles = files("/path/to/jacoco/exec/file.exec") violationRules { // ... } } } } ``` -------------------------------- ### Configure Gradle Signing Plugin Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/signing.md Apply the signing plugin and configure it to use your GPG key and passphrase for signing artifacts. ```kts plugins { signing } signing { val keyId = "" // read from property 'signing.keyId' val secretKey = "" // read from property 'signing.secretKey' val signingPassword = "" // read from property 'signing.password' seInMemoryPgpKeys(keyId, secretKey, signingPassword) } ``` -------------------------------- ### Configure All Entities at Once (Groovy DSL) Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/violation-rules.md Set a single minimum coverage ratio for all entities (LINE, BRANCH, INSTRUCTION) using Groovy DSL. ```groovy violationRules { all { minCoverageRatio = 0.8 } } ``` -------------------------------- ### JSON Configuration for Delta Coverage Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/delta-coverage-cli/README.md Configure Delta Coverage using a JSON file for complex setups. Supports glob patterns within file lists. ```json { "coverageEngine": "JACOCO", "viewName": "cli-run", "diffSourceFile": "changes.diff", "coverageBinaryFiles": [ "build/jacoco/test.exec", "build/**/jacoco/*.exec" ], "classRoots": ["build/classes/java/main"], "sourceFiles": ["src/main/java", "src/main/kotlin"], "excludeClasses": ["**/*Test*"], "reports": { "reportDir": "build/reports/delta-coverage", "html": true, "xml": false, "console": true, "markdown": false, "fullCoverage": false }, "violationRules": { "minCoverage": 0.8, "failOnViolation": true } } ``` -------------------------------- ### Delta Coverage CLI Usage Help Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/delta-coverage-cli/README.md Displays the command-line usage and available options for the Delta Coverage CLI. This includes options for configuration files, coverage engines, diff files, binary and source directories, reporting formats, and violation thresholds. ```text Usage: delta-coverage [-hvV] [--console] [--fail-on-violation] [--full-coverage] [--html] [--markdown] [--xml] [-c=] [-e=] [-f=] [--min-coverage=] [-o=] [--view-name=] [--classes=...] [--coverage-binary=...] [--exclude=...] [-s=...] Computes code coverage of new/modified code based on a provided diff. Options: -c, --config= Path to configuration file (YAML or JSON) -e, --engine= Coverage engine: JACOCO or INTELLIJ -f, --diff-file= Path to diff file --coverage-binary= Coverage binary files or glob pattern --classes= Class directories or glob pattern -s, --sources= Source directories (comma-separated or glob) --exclude= Class exclusion patterns (comma-separated) -o, --report-dir= Output directory for reports --html Generate HTML report --xml Generate XML report --console Generate console report --markdown Generate markdown report --full-coverage Include full coverage in reports --min-coverage= Minimum coverage ratio (0.0-1.0) --fail-on-violation Exit with error if coverage below threshold --view-name= Name for the coverage view -v, --verbose Enable verbose output -V, --version Print version information -h, --help Show help message ``` -------------------------------- ### YAML Configuration for Delta Coverage Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/delta-coverage-cli/README.md Configure Delta Coverage using a YAML file for complex setups. Supports glob patterns within file lists. ```yaml # delta-coverage.yaml coverageEngine: JACOCO viewName: cli-run diffSourceFile: changes.diff coverageBinaryFiles: - build/jacoco/test.exec - "build/**/jacoco/*.exec" # Glob patterns supported classRoots: - build/classes/java/main sourceFiles: - src/main/java - src/main/kotlin excludeClasses: - "**/*Test*" reports: reportDir: build/reports/delta-coverage html: true xml: false console: true markdown: false fullCoverage: false violationRules: minCoverage: 0.8 failOnViolation: true ``` -------------------------------- ### Run Delta Coverage Locally Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/comparison/vs-sonarqube.md Execute the Delta Coverage Gradle task to get coverage statistics for changed code. This provides fast feedback in seconds. ```bash ./gradlew test deltaCoverage ``` -------------------------------- ### Configure All Entities at Once (Kotlin DSL) Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/violation-rules.md Set a single minimum coverage ratio for all entities (LINE, BRANCH, INSTRUCTION) using Kotlin DSL. ```kotlin violationRules { all { minCoverageRatio.set(0.8) } } ``` -------------------------------- ### Run Delta Coverage CLI with Configuration File Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/violation-rules.md Execute the delta coverage CLI tool using a configuration file for advanced settings, such as per-entity thresholds. This approach is recommended for complex configurations that mirror Gradle DSL settings. ```bash java -jar delta-coverage-cli.jar --config delta-coverage.yaml ``` -------------------------------- ### View-Specific Class Filters Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/report-views.md Configure class filters for a custom view to include specific classes and exclude others. This example sets filters for a view named 'apiTests'. ```kotlin view("apiTests") { // Only include API classes includeClasses.value(listOf("**/api/**/*.class")) // Exclude generated code excludeClasses.value(listOf("**/generated/**/*.class")) } ``` -------------------------------- ### Enable Full Coverage Reports Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/recipes/legacy-projects.md Enable full coverage reports to track the overall project coverage progress alongside delta coverage. ```kotlin reports { fullCoverageReport.set(true) } ``` -------------------------------- ### Update Report View Registration for v3.x Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/getting-started/migration.md When migrating to v3.x, report views are auto-discovered. Remove manual registration and use the 'by getting' syntax for existing views. ```kotlin configure { reportViews { register("test") { // configuration } } } ``` ```kotlin configure { reportViews { val test by getting { // configuration } } } ``` -------------------------------- ### Run CLI with Configuration File Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/delta-coverage-cli/README.md Execute the Delta Coverage CLI using a specified YAML or JSON configuration file. ```bash java -jar delta-coverage-cli.jar --config delta-coverage.yaml # or java -jar delta-coverage-cli.jar --config delta-coverage.json ``` -------------------------------- ### DeltaCoverageTestListener Implementation Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/adr/test-to-code-mapping-adr.md Implements the TestExecutionListener interface to integrate with the testing framework. It starts and stops the StackSampler for each test execution, ensuring that samples are correctly associated with the current test. ```kotlin class DeltaCoverageTestListener : TestExecutionListener { override fun executionStarted(testIdentifier: TestIdentifier) { if (testIdentifier.isTest) { sampler.setCurrentTest(testIdentifier) } } override fun executionFinished(testIdentifier: TestIdentifier, result: TestExecutionResult) { if (testIdentifier.isTest) { sampler.clearCurrentTest() } } } ``` -------------------------------- ### Configure Per-Entity Rules (Groovy DSL) Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/violation-rules.md Set distinct minimum coverage thresholds for LINE, BRANCH, and INSTRUCTION entities using Groovy DSL. ```groovy violationRules { rule(CoverageEntity.LINE) { minCoverageRatio = 0.8 } rule(CoverageEntity.BRANCH) { minCoverageRatio = 0.7 } rule(CoverageEntity.INSTRUCTION) { minCoverageRatio = 0.9 } } ``` -------------------------------- ### Configure Plugin Repositories Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/guides/kotlin-projects.md Add necessary repositories to settings.gradle.kts to resolve the CoverJet plugin if 'Cannot find CoverJet plugin' error occurs. ```kotlin pluginManagement { repositories { gradlePluginPortal() mavenCentral() } } ``` -------------------------------- ### Configure Per-Entity Rules (Kotlin DSL) Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/violation-rules.md Set distinct minimum coverage thresholds for LINE, BRANCH, and INSTRUCTION entities using Kotlin DSL. ```kotlin violationRules { rule(CoverageEntity.LINE) { minCoverageRatio.set(0.8) } rule(CoverageEntity.BRANCH) { minCoverageRatio.set(0.7) } rule(CoverageEntity.INSTRUCTION) { minCoverageRatio.set(0.9) } } ``` -------------------------------- ### Configure Gradle Signing Properties Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/signing.md Add your GPG key ID, passphrase, and secret key to the `~/.gradle/gradle.properties` file for Gradle to use. ```properties signing.keyId= signing.password= # Set : signing.secretKey=-----BEGIN PGP PRIVATE KEY BLOCK----- next-key-lines ... -----END PGP PRIVATE KEY BLOCK----- ``` -------------------------------- ### Run CLI with Glob Patterns Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/delta-coverage-cli/README.md Use glob patterns for file arguments like coverage binaries, class roots, and source files to automatically discover relevant files. ```bash java -jar delta-coverage-cli.jar \ --engine JACOCO \ --diff-file changes.diff \ --coverage-binary 'build/**/jacoco/*.exec' \ --classes 'build/classes/**/main' \ --sources 'src/main/java,src/main/kotlin' \ --html --console ``` -------------------------------- ### Run IntelliJ Coverage Engine via CLI Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/coverage-engines.md Execute the IntelliJ coverage engine using the command-line interface. Requires specifying diff file, coverage binary, classes, and sources. ```bash java -jar delta-coverage-cli.jar \ --engine INTELLIJ \ --diff-file changes.diff \ --coverage-binary build/coverage/test.ic \ --classes build/classes/kotlin/main \ --sources src/main/kotlin \ --console ``` -------------------------------- ### Kotlin DSL Shorthand for Per-Entity Rules Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/violation-rules.md A concise way to set minimum coverage ratios for LINE and BRANCH entities using Kotlin DSL shorthand. ```kotlin violationRules { CoverageEntity.LINE { minCoverageRatio.set(0.8) } CoverageEntity.BRANCH { minCoverageRatio.set(0.7) } } ``` -------------------------------- ### Custom View for Controller E2E Coverage Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/report-views.md Create a custom view for controller classes using E2E tests. This example includes controller classes, specifies coverage from a specific E2E test execution file, and sets a 70% coverage threshold. ```kotlin reportViews { val controllers by creating { includeClasses.value(listOf("**/controller/**/*Controller*")) coverageBinaryFiles = files("build/jacoco/e2eTest.exec") violationRules.failIfCoverageLessThan(0.7) } } ``` -------------------------------- ### Custom View for Repository Coverage Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/report-views.md Create a custom view to enforce coverage rules specifically for repository classes using integration tests. This example includes repository classes, specifies coverage from integration tests, and sets a 80% coverage threshold. ```kotlin reportViews { val repository by creating { // Only include repository classes includeClasses.value(listOf( "**/infrastructure/**/*Repository*" )) // Use coverage from integration tests only coverageBinaryFiles = project(":integration-tests") .layout.buildDirectory.asFileTree.matching { include("**/jacoco/*.exec") } // Enforce 80% coverage violationRules.failIfCoverageLessThan(0.8) } } ``` -------------------------------- ### Trunk-Based Development Workflow Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/CONTRIBUTING.md Illustrates the standard workflow for developing features in a trunk-based model. Create feature branches from main, develop, and merge back via pull requests. ```text main ●──●──●──●──────●──●──●──● \ feature ●──●──● ``` -------------------------------- ### Run Delta Coverage CLI with Basic Options Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/violation-rules.md Execute the delta coverage CLI tool with essential parameters for diff file, engine, coverage binary, class paths, sources, minimum coverage, and console/HTML reporting. This command is useful for CI environments. ```bash java -jar delta-coverage-cli.jar \ --diff-file changes.diff \ --engine JACOCO \ --coverage-binary build/jacoco/test.exec \ --classes build/classes/java/main \ --sources src/main/java \ --min-coverage 0.8 \ --fail-on-violation \ --console --html ``` -------------------------------- ### GitHub Actions Deployment Workflow Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/adr/landing-page-adr.md Configures a GitHub Actions workflow to automatically deploy documentation on pushes to the main branch. Requires Python 3.12 and mkdocs-material. ```yaml # .github/workflows/deploy-docs.yml name: Deploy docs on: push: branches: [main] paths: ['docs/**', 'mkdocs.yml'] jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: python-version: '3.12' - run: pip install mkdocs-material - run: mkdocs gh-deploy --force ``` -------------------------------- ### Configure Delta Coverage for Legacy Projects Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/recipes/legacy-projects.md Set up Delta Coverage to compare against a remote branch, enable HTML and full coverage reports, and define an initial violation threshold for new code. ```kotlin configure { diffSource.git.compareWith("refs/remotes/origin/main") reports { html.set(true) fullCoverageReport.set(true) // Track overall progress } reportViews { val test by getting { violationRules.failIfCoverageLessThan(0.8) // Start at 80% } } } ``` -------------------------------- ### Build Delta Coverage CLI JAR Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/delta-coverage-cli/README.md Clone the repository and use Gradle to build the shadow JAR for the CLI. The resulting JAR file will be located in the build/libs directory. ```bash # Clone the repository git clone https://github.com/gw-kit/delta-coverage-plugin.git cd delta-coverage-plugin # Build the CLI JAR ./gradlew :delta-coverage-cli:shadowJar # The JAR is located at: # delta-coverage-cli/build/libs/delta-coverage-cli-.jar ``` -------------------------------- ### GitHub Actions CI with Delta Coverage CLI Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/guides/ci-integration.md This workflow uses the Delta Coverage CLI to generate and analyze coverage reports. It requires downloading the CLI, generating a diff file, and specifying paths for coverage data and class files. The `fetch-depth: 0` is crucial for accurate diff calculation. ```yaml name: Build on: pull_request: branches: [main] jobs: coverage: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - uses: actions/setup-java@v4 with: java-version: '17' distribution: 'temurin' - name: Build and test run: ./gradlew build - name: Generate diff run: git diff origin/${{ github.base_ref }}...HEAD > changes.diff - name: Download Delta Coverage CLI run: | curl -L -o delta-coverage-cli.jar \ https://repo1.maven.org/maven2/io/github/gw-kit/delta-coverage-cli/3.6.0/delta-coverage-cli-3.6.0.jar - name: Run Delta Coverage run: | java -jar delta-coverage-cli.jar \ --engine JACOCO \ --diff-file changes.diff \ --coverage-binary 'build/**/jacoco/*.exec' \ --classes 'build/classes/**/main' \ --sources src/main/java \ --html --console \ --min-coverage 0.8 \ --fail-on-violation - name: Upload coverage report uses: actions/upload-artifact@v4 if: always() with: name: delta-coverage-report path: build/reports/delta-coverage ``` -------------------------------- ### GitLab CI with CLI Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/guides/ci-integration.md Set up GitLab CI to use the Delta Coverage CLI for generating reports. This involves downloading the CLI, generating a diff, and running the Java application. ```yaml stages: - test delta-coverage: stage: test image: eclipse-temurin:17-jdk script: - ./gradlew build - git diff origin/main...HEAD > changes.diff - | curl -L -o delta-coverage-cli.jar \ https://repo1.maven.org/maven2/io/github/gw-kit/delta-coverage-cli/3.6.0/delta-coverage-cli-3.6.0.jar - | java -jar delta-coverage-cli.jar \ --engine JACOCO \ --diff-file changes.diff \ --coverage-binary 'build/**/jacoco/*.exec' \ --classes 'build/classes/**/main' \ --sources src/main/java \ --html --console \ --min-coverage 0.8 \ --fail-on-violation artifacts: when: always paths: - build/reports/delta-coverage expire_in: 1 week ``` -------------------------------- ### Run Gradle Tests and Delta Coverage Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/faq.md Execute tests and then the deltaCoverage task. Ensure coverage binary files exist by checking the build directory. ```bash ./gradlew test deltaCoverage ``` ```bash find build -name "*.exec" ``` -------------------------------- ### Jenkins Declarative Pipeline with CLI Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/guides/ci-integration.md Set up a Jenkins Declarative Pipeline to use the Delta Coverage CLI. This includes building the project, generating a diff, downloading the CLI, and running it. ```groovy pipeline { agent any stages { stage('Build') { steps { sh './gradlew build' } } stage('Delta Coverage') { steps { sh 'git diff origin/main...HEAD > changes.diff' sh ''' curl -L -o delta-coverage-cli.jar \ https://repo1.maven.org/maven2/io/github/gw-kit/delta-coverage-cli/3.6.0/delta-coverage-cli-3.6.0.jar ''' sh ''' java -jar delta-coverage-cli.jar \ --engine JACOCO \ --diff-file changes.diff \ --coverage-binary 'build/**/jacoco/*.exec' \ --classes 'build/classes/**/main' \ --sources src/main/java \ --html --console \ --fail-on-violation } } } post { always { publishHTML(target: [ reportDir: 'build/reports/delta-coverage', reportFiles: 'html/index.html', reportName: 'Delta Coverage' ]) } } } ``` -------------------------------- ### Verify Coverage Binary Path with Glob Patterns Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/faq.md When using the CLI, ensure the --coverage-binary argument points to existing files. Glob patterns can be used for automatic discovery. ```bash --coverage-binary 'build/**/jacoco/*.exec' ``` -------------------------------- ### Azure Pipelines with CLI Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/guides/ci-integration.md Set up Azure Pipelines to use the Delta Coverage CLI for build, diff generation, and coverage analysis. ```yaml trigger: - main pool: vmImage: 'ubuntu-latest' steps: - task: JavaToolInstaller@0 inputs: versionSpec: '17' jdkArchitectureOption: 'x64' jdkSourceOption: 'PreInstalled' - script: ./gradlew build displayName: 'Build and test' - script: git diff origin/main...HEAD > changes.diff displayName: 'Generate diff' - script: | curl -L -o delta-coverage-cli.jar \ https://repo1.maven.org/maven2/io/github/gw-kit/delta-coverage-cli/3.6.0/delta-coverage-cli-3.6.0.jar java -jar delta-coverage-cli.jar \ --engine JACOCO \ --diff-file changes.diff \ --coverage-binary '$(Build.SourcesDirectory)/build/**/jacoco/*.exec' \ --classes '$(Build.SourcesDirectory)/build/classes/**/main' \ --sources $(Build.SourcesDirectory)/src/main/java \ --report-dir $(Build.ArtifactStagingDirectory)/delta-coverage \ --html --console \ --fail-on-violation displayName: 'Run Delta Coverage' - task: PublishBuildArtifacts@1 condition: always() inputs: pathToPublish: '$(Build.ArtifactStagingDirectory)/delta-coverage' artifactName: 'delta-coverage-report' ``` -------------------------------- ### GitHub Actions CI with Gradle Plugin Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/guides/ci-integration.md This workflow runs tests with Delta Coverage enabled using the Gradle plugin. Ensure `fetch-depth: 0` is set for `actions/checkout` to provide the necessary git history for diff computation. ```yaml name: Build on: pull_request: branches: [main] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 # Required for git diff - uses: actions/setup-java@v4 with: java-version: '17' distribution: 'temurin' - name: Run tests with coverage run: ./gradlew test deltaCoverage ``` -------------------------------- ### CircleCI Configuration for Delta Coverage CLI Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/guides/ci-integration.md This configuration demonstrates how to use the Delta Coverage CLI within CircleCI. It includes steps for building, generating a diff, running the CLI tool with specified parameters, and storing the generated reports. ```yaml version: 2.1 jobs: build: docker: - image: cimg/openjdk:17.0 steps: - checkout - run: name: Build and test command: ./gradlew build - run: name: Generate diff command: git diff origin/main...HEAD > changes.diff - run: name: Run Delta Coverage command: | curl -L -o delta-coverage-cli.jar \ https://repo1.maven.org/maven2/io/github/gw-kit/delta-coverage-cli/3.6.0/delta-coverage-cli-3.6.0.jar java -jar delta-coverage-cli.jar \ --engine JACOCO \ --diff-file changes.diff \ --coverage-binary 'build/**/jacoco/*.exec' \ --classes 'build/classes/**/main' \ --sources src/main/java \ --html --console \ --fail-on-violation - store_artifacts: path: build/reports/delta-coverage destination: delta-coverage-report ``` -------------------------------- ### Publish GPG Public Key Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/signing.md Upload your public GPG key to a keyserver so others can verify your signatures. ```bash gpg --keyserver hkps://keys.openpgp.org --send-keys ``` -------------------------------- ### Enable Markdown Report Generation Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/reports.md Configure the build script to enable Markdown report generation. This is useful for integrating coverage reports into PR comments or other documentation. ```kotlin reports { markdown.set(true) } ``` ```groovy reports { markdown = true } ``` -------------------------------- ### Enable Full Coverage Reports in Gradle Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/recipes/coverage-badges.md Configure your Gradle build to generate full coverage reports alongside delta reports. This is necessary for creating overall project coverage badges. ```kotlin configure { diffSource.git.compareWith("refs/remotes/origin/main") reports { xml.set(true) fullCoverageReport.set(true) } } ``` -------------------------------- ### Default Report Output Structure (Gradle Plugin) Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/reports.md Illustrates the default directory structure for reports generated by the Gradle plugin, including HTML, XML, and Markdown outputs within a view-specific subdirectory. ```text build/reports/coverage-reports/ └── delta-coverage/ └── test/ ├── html/ │ └── index.html ├── report.xml └── report.md ``` -------------------------------- ### Enable Markdown Reports in Gradle Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/guides/pr-comments.md Configure your Gradle build to generate markdown reports for Delta Coverage. This is a prerequisite for the PR comment action. ```kotlin configure { diffSource.git.compareWith("refs/remotes/origin/main") reports { markdown.set(true) } } ``` -------------------------------- ### Download Diff from URL for CLI Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/diff-sources.md The CLI does not fetch diffs from URLs directly. Use 'curl' to download the diff file first, then provide it to the CLI using the '--diff-file' argument. ```bash curl -L -o changes.diff \ "https://github.com/owner/repo/compare/main...feature.diff" ``` -------------------------------- ### Run Delta Coverage CLI with Git Diff File Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/configuration/diff-sources.md Execute the Delta Coverage CLI using a pre-generated diff file. Ensure all necessary arguments like engine, coverage binary, classes, and sources are provided. ```bash java -jar delta-coverage-cli.jar \ --diff-file changes.diff \ --engine JACOCO \ --coverage-binary build/jacoco/test.exec \ --classes build/classes/java/main \ --sources src/main/java \ --console ``` -------------------------------- ### Verify Coverage Files Source: https://github.com/gw-kit/delta-coverage-plugin/blob/main/docs/guides/kotlin-projects.md Check for the presence of .ic coverage files in the build directory to ensure test tasks ran correctly. ```bash find build -name "*.ic" ```