{"id":15622770,"url":"https://github.com/nbaztec/coveralls-jacoco-gradle-plugin","last_synced_at":"2025-04-15T22:50:30.521Z","repository":{"id":45049800,"uuid":"282430682","full_name":"nbaztec/coveralls-jacoco-gradle-plugin","owner":"nbaztec","description":"Coveralls JaCoCo Gradle plugin","archived":false,"fork":false,"pushed_at":"2024-05-06T15:34:43.000Z","size":226,"stargazers_count":23,"open_issues_count":3,"forks_count":15,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-29T02:12:07.612Z","etag":null,"topics":["circleci","coveralls","gradle","jacoco","java","kotlin","travis"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nbaztec.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-25T11:31:43.000Z","updated_at":"2024-06-27T09:27:09.000Z","dependencies_parsed_at":"2024-10-22T21:33:45.263Z","dependency_job_id":null,"html_url":"https://github.com/nbaztec/coveralls-jacoco-gradle-plugin","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nbaztec%2Fcoveralls-jacoco-gradle-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nbaztec%2Fcoveralls-jacoco-gradle-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nbaztec%2Fcoveralls-jacoco-gradle-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nbaztec%2Fcoveralls-jacoco-gradle-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nbaztec","download_url":"https://codeload.github.com/nbaztec/coveralls-jacoco-gradle-plugin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249167434,"owners_count":21223505,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["circleci","coveralls","gradle","jacoco","java","kotlin","travis"],"created_at":"2024-10-03T09:55:09.118Z","updated_at":"2025-04-15T22:50:30.504Z","avatar_url":"https://github.com/nbaztec.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Coveralls Jacoco Gradle Plugin\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) ![Deployment Status](https://github.com/nbaztec/coveralls-jacoco-gradle-plugin/workflows/check/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/nbaztec/coveralls-jacoco-gradle-plugin/badge.svg?branch=main)](https://coveralls.io/github/nbaztec/coveralls-jacoco-gradle-plugin?branch=main)\n\nA jacoco test coverage reporter gradle plugin for [coveralls.io](https://coveralls.io).\n\nThe plugin supports non-root packages in line with the recommended [Kotlin directory structure](https://kotlinlang.org/docs/reference/coding-conventions.html#directory-structure) \nwhich was missing in many other plugins for the Kotlin ecosystem. \n\nThe plugin automatically detects the root package, if it conforms to Kotlin guidelines and has a `.kt` file on the root level.\n\n## Usage\n\n[Gradle Plugin page](https://plugins.gradle.org/plugin/com.github.nbaztec.coveralls-jacoco)\n\nApply the plugin with the ID: `com.github.nbaztec.coveralls-jacoco`. \n\n```kotlin\n// build.gradle.kts\n\nbuildscript {\n    repositories {\n        mavenCentral()\n        jcenter()\n    }\n}\n\nplugins {\n    jacoco\n    id(\"com.github.nbaztec.coveralls-jacoco\") version \"1.2.20\"\n}\n```\n\nThis will add a gradle task `coverallsJacoco` that can be used to publish coverage report via \n```bash\n$ ./gradlew test jacocoTestReport coverallsJacoco\n```\n\nSet the value of `COVERALLS_REPO_TOKEN` from the project page on coveralls.io\n\nAdditionally, the following coveralls parameters may be specified via environment variables:\n* `COVERALLS_PARALLEL` (`true`/`false`)\n* `COVERALLS_FLAG_NAME`\n\n## Options\n```kotlin\n// build.gradle.kts\n\ncoverallsJacoco {\n    reportPath = \"\" // default: \"build/reports/jacoco/test/jacocoTestReport.xml\"\n\n    reportSourceSets += sourceSets.foo.allJava.srcDirs + sourceSets.bar.allJava.srcDirs // default: main\n    apiEndpoint = \"\" // default: https://coveralls.io/api/v1/jobs \n    \n    dryRun = false // default: false\n    coverallsRequest = File(\"build/req.json\") // default: null\n}\n```\n\n* `reportPath: String` - location of the jacoco xml report.\n* `reportSourceSets: Iterable\u003cFile\u003e` - a list of directories where to find the source code in.\n* `apiEndpoint: String` - coveralls api endpoint for posting jobs.\n* `dryRun: Boolean` - executes the task without posting to coveralls. Useful for debugging.\n* `coverallsRequest: File` - writes the coveralls request payload to a file. Useful for debugging.\n\n## Excluding Files\nPlease refer to the official JaCoCo documentation to exclude files from the report. An example configuration is as follows:\n```\njacocoTestReport {\n    afterEvaluate {\n        classDirectories = files(classDirectories.files.collect {\n            fileTree(dir: it, exclude: \"com/foo/**\")\n        })\n    }\n}\n```\n\n## Multi-Project Support - Pure Kotlin/Java\nIt is recommended to use the [JaCoCo Aggregation plugin](https://docs.gradle.org/current/userguide/jacoco_report_aggregation_plugin.html) to consolidate\nthe test reports. Please refer to the [sample](https://docs.gradle.org/current/samples/sample_jvm_multi_project_with_code_coverage_standalone.html) on the website, on how to configure the plugin, \nand specify the output file in the `coverallsJacoco` config.\n\n```kotlin\ncoverallsJacoco {\n    reportPath = \"build/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml\"\n}\n```\n\nThe `jacoco-report-aggregation` plugin must be configured in the same project as this plugin, regardless whether it is\nconfigured in the root project or a standalone utility subproject.\n\n## (Not Recommended) Multi-Project Support - Pure Kotlin/Java\nTo consolidate multiple JaCoCo coverage reports, the following code can be used to add a new task `codeCoverageReport`\n```kotlin\ntasks.register\u003cJacocoReport\u003e(\"codeCoverageReport\") {\n    val jacocoReportTask = this\n\n    // If a subproject applies the 'jacoco' plugin, add the result it to the report\n    subprojects {\n        val subproject = this\n        subproject.plugins.withType\u003cJacocoPlugin\u003e().configureEach {\n            subproject.tasks.matching({ it.extensions.findByType\u003cJacocoTaskExtension\u003e() != null }).configureEach {\n                val testTask = this\n                sourceSets(subproject.sourceSets.main.get())\n                executionData(testTask)\n            }\n\n            // To automatically run `test` every time `./gradlew codeCoverageReport` is called,\n            // you may want to set up a task dependency between them as shown below.\n            // Note that this requires the `test` tasks to be resolved eagerly (see `forEach`) which\n            // may have a negative effect on the configuration time of your build.\n            subproject.tasks.matching({ it.extensions.findByType\u003cJacocoTaskExtension\u003e() != null }).forEach {\n                rootProject.tasks[\"codeCoverageReport\"].dependsOn(it)\n            }\n        }\n    }\n\n\n    // enable the different report types (html, xml, csv)\n    reports {\n        // xml is usually used to integrate code coverage with\n        // other tools like SonarQube, Coveralls or Codecov\n        xml.isEnabled = true\n\n        // HTML reports can be used to see code coverage\n        // without any external tools\n        html.isEnabled = true\n    }\n\n    coverallsJacoco.dependsOn(jacocoReportTask)\n}\n```\n\n## (Not Recommended) Multi-Project Support - Android\n\nTo consolidate multiple JaCoCo coverage reports on Android multi-project configurations, the following code can be used to add a new task `jacocoFullReport`\n\n### Groovy DSL `build.gradle`\n```groovy\n// ignore any subproject, if required `subprojects.findAll{ it.name != 'customSubProject' }`\ndef coveredProjects = subprojects\n\n// configure() method takes a list as an argument and applies the configuration to the projects in this list.\nconfigure(coveredProjects) { p -\u003e\n    p.evaluate()\n\n    // Here we apply jacoco plugin to every project\n    apply plugin: 'jacoco'\n    // Set Jacoco version\n    jacoco {\n        toolVersion = \"0.8.5\"\n    }\n\n    // Here we create the task to generate Jacoco report\n    // It depends to unit test task we don't have to manually running unit test before the task\n    task jacocoReport(type: JacocoReport, dependsOn: 'test') {\n\n        // Define what type of report we should generate\n        // If we don't want to process the data further, html should be enough\n        reports {\n            xml.enabled = true\n            html.enabled = true\n        }\n\n        // Setup the .class, source, and execution directories\n        final fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', 'android/**/*.*']\n\n        sourceDirectories.setFrom files([\"${p.projectDir}/src/main/java\"])\n        classDirectories.setFrom files([\n            fileTree(dir: \"${p.buildDir}/classes\", excludes: fileFilter),\n            fileTree(dir: \"${p.buildDir}/intermediates/javac/debug\", excludes: fileFilter),\n            fileTree(dir: \"${p.buildDir}/tmp/kotlin-classes/debug\", excludes: fileFilter),\n        ])\n        executionData.setFrom fileTree(dir: p.buildDir, includes: [\n                'jacoco/*.exec', 'outputs/code-coverage/connected/*coverage.ec'\n        ])\n    }\n}\n\napply plugin: 'jacoco'\napply plugin: 'com.github.nbaztec.coveralls-jacoco'\n\ntask jacocoFullReport(type: JacocoReport, group: 'Coverage reports') {\n    def projects = coveredProjects\n\n    // Here we depend on the jacocoReport task that we created before\n    dependsOn(projects.jacocoReport)\n\n    final source = files(projects.jacocoReport.sourceDirectories)\n\n    additionalSourceDirs.setFrom source\n    sourceDirectories.setFrom source\n\n    classDirectories.setFrom files(projects.jacocoReport.classDirectories)\n    executionData.setFrom files(projects.jacocoReport.executionData)\n\n    reports {\n        html {\n            enabled true\n            destination file(\"$buildDir/reports/jacoco/html\")\n        }\n        xml {\n            enabled true\n            destination file(\"$buildDir/reports/jacoco/jacocoFullReport.xml\")\n        }\n    }\n\n    doFirst {\n        executionData.setFrom files(executionData.findAll { it.exists() })\n    }\n\n    coverallsJacoco {\n        reportPath = \"$buildDir/reports/jacoco/jacocoFullReport.xml\"\n        reportSourceSets =  projects.jacocoReport.sourceDirectories.collect{ it.getFiles() }.flatten()\n    }\n\n    tasks.coverallsJacoco.dependsOn(it)\n}\n```\n\n### Kotlin DSL `build.gradle.kts`\n```kotlin\n\n// ignore any subproject, if required `subprojects.findAll{ it.name != 'customSubProject' }`\nval coveredProjects = subprojects\n\n// configure() method takes a list as an argument and applies the configuration to the projects in this list.\nconfigure(coveredProjects) {\n    val p = (this as org.gradle.api.internal.project.DefaultProject)\n    p.evaluate()\n\n    // Here we apply jacoco plugin to every project\n    apply(jacoco)\n\n    // Set Jacoco version\n    jacoco {\n        toolVersion = \"0.8.5\"\n    }\n\n    // Here we create the task to generate Jacoco report\n    // It depends to unit test task we don't have to manually running unit test before the task\n    p.task(\"jacocoReport\", JacocoReport::class) {\n\n        // Define what type of report we should generate\n        // If we don't want to process the data further, html should be enough\n        reports {\n            xml.isEnabled = true\n            html.isEnabled = true\n        }\n\n        // Setup the .class, source, and execution directories\n        val fileTreeConfig: (ConfigurableFileTree) -\u003e Unit = {\n            it.exclude(\"**/R.class\", \"**/R$*.class\", \"**/BuildConfig.*\", \"**/Manifest*.*\", \"android/**/*.*\")\n        }\n\n        sourceDirectories.setFrom(files(\"${p.projectDir}/src/main/java\"))\n        classDirectories.setFrom(listOf(\n            fileTree(\"${p.buildDir}/classes\", fileTreeConfig),\n            fileTree(\"${p.buildDir}/intermediates/javac/debug\", fileTreeConfig),\n            fileTree(\"${p.buildDir}/tmp/kotlin-classes/debug\", fileTreeConfig)\n        ))\n        executionData.setFrom(fileTree(p.buildDir) {\n            include(\"jacoco/*.exec\", \"outputs/code-coverage/connected/*coverage.ec\")\n        })\n    }.dependsOn(\"test\")\n}\n\nplugins {\n    jacoco\n    id(\"com.github.nbaztec.coveralls-jacoco\") version \"1.2.4\"\n}\n\ntasks {\n    register(\"jacocoFullReport\", JacocoReport::class) {\n        val jacocoReportTask = this\n\n        group = \"Coverage reports\"\n        val projects = coveredProjects\n\n        // Here we depend on the jacocoReport task that we created before\n        val subTasks = projects.map { it.task\u003cJacocoReport\u003e(\"jacocoReport\") }\n        dependsOn(subTasks)\n\n        val subSourceDirs = subTasks.map { files(it.sourceDirectories) }\n        additionalSourceDirs.setFrom(subSourceDirs)\n        sourceDirectories.setFrom(subSourceDirs)\n\n        classDirectories.setFrom(subTasks.map { files(it.classDirectories) })\n        executionData.setFrom(subTasks.map { files(it.executionData) })\n\n        reports {\n            html.isEnabled = true\n            html.destination = file(\"$buildDir/reports/jacoco/html\")\n\n            xml.isEnabled = true\n            xml.destination = file(\"$buildDir/reports/jacoco/jacocoFullReport.xml\")\n        }\n\n        doFirst {\n            executionData.setFrom(files(executionData.filter { it.exists() }))\n        }\n\n        coverallsJacoco {\n            dependsOn(jacocoReportTask)\n\n            reportPath = \"$buildDir/reports/jacoco/jacocoFullReport.xml\"\n            reportSourceSets = subSourceDirs.flatMap { it.files }\n        }\n    }\n}\n```\n\n## CI Usage\nThe plugin can be used with the following CI providers:\n\n* Travis-CI \u0026 Travis-Pro\n* CircleCI\n* Github Actions\n* Jenkins\n* Codeship\n* Buildkite\n* Gitlab CI\n* Bitrise\n\n\n### Travis\nSet the `COVERALLS_REPO_TOKEN` via [Environment Variables](https://docs.travis-ci.com/user/environment-variables/) or [Encryption Keys](https://docs.travis-ci.com/user/encryption-keys/) and set up a job as follows:\n\n```yaml\nlanguage: java\nscript: ./gradlew test jacocoTestReport coverallsJacoco\n```\n\n### CircleCI\nSet the `COVERALLS_REPO_TOKEN` via CircleCI's [Environment Variables](https://circleci.com/docs/2.0/env-vars/) and set up a job as follows:\n```yaml\njobs:\n  check:\n    docker:\n      - image: amazoncorretto:11\n    steps:\n      - run: ./gradlew test jacocoTestReport coverallsJacoco\n```\n\n### Github Actions\nSet the `COVERALLS_REPO_TOKEN` via Github's [Environment Variables](https://docs.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables) or [Secrets](https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets) and set up a job as follows:\n```yaml\njobs:\n  tests:\n    runs-on: ubuntu-latest\n    steps:\n    - uses: actions/checkout@v2\n      with:\n        ref: ${{ github.event.pull_request.head.sha }}\n    - name: test and publish coverage\n      env:\n        COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}\n      run: ./gradlew test jacocoTestReport coverallsJacoco\n```\n\nFor running on publicly forked PRs, the plugin uses a (undocumented) API and uses `GITHUB_TOKEN` to identify the repo instead, as follows:\n```yaml\njobs:\n  tests:\n    runs-on: ubuntu-latest\n    steps:\n    - uses: actions/checkout@v2\n      with:\n        ref: ${{ github.event.pull_request.head.sha }}\n    - name: test and publish coverage\n      env:\n        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n      run: ./gradlew test jacocoTestReport coverallsJacoco\n```\n### Buildkite\n\nSee Buildkite environment variables [documentation](https://buildkite.com/docs/pipelines/environment-variables#defining-your-own)\n\n### Gitlab CI\n\nSee Gitlab CI predefined variables [documentation](https://docs.gitlab.com/ee/ci/variables/predefined_variables.html)\n\n### Bitrise CI\n\nSee Bitrise CI predefined variables [documentation](https://devcenter.bitrise.io/builds/available-environment-variables/)\n\n### Other CI\n\nFor [other CIs](https://docs.coveralls.io/supported-ci-services#insert-your-ci-here), the following default environment variables are supported:\n\n```\nCI_NAME\nCI_BUILD_NUMBER\nCI_BUILD_URL\nCI_BRANCH\nCI_PULL_REQUEST\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnbaztec%2Fcoveralls-jacoco-gradle-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnbaztec%2Fcoveralls-jacoco-gradle-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnbaztec%2Fcoveralls-jacoco-gradle-plugin/lists"}