This Gradle plugin supports automatically gathering and publishing
the XML test results to the Projektor server. It listens to the
end of the build, gathers up all the XML results generated by
Test
tasks in the build, then sends those to the Projektor server.
Example Projektor report from the plugin’s build: https://projektorlive.herokuapp.com/tests/8VQSLOBCSCWA
To apply this plugin to your project:
plugins {
id "dev.projektor.publish" version "9.0.0"
}
See https://plugins.gradle.org/plugin/dev.projektor.publish for the latest version.
By default the plugin publishes results from all Test
tasks in the project
when the build finishes.
The plugin also adds a publishResults
task that lets you publish test
results from a build after it has executed (for example, if you didn’t have auto-publish on)
This can be a good way to easily share a specific test failure with colleagues.
./gradlew publishResults
Note: If you have a multi-project build, please apply the plugin to the root project.
All the configuration of the plugin is inside the projektor
block.
To use the plugin, first set the URL of the Projektor server:
projektor {
serverUrl = "https://myserver"
}
You can also include results from arbitrary directories in your build with the additionalResultsDirs
configuration option:
projektor {
serverUrl = "https://myserver"
additionalResultsDirs = ['build/testResultsDir']
}
The plugin includes configurable retry and timeout settings to help make publishing results to the Projektor server more resilient against network hiccups:
projektor {
serverUrl = "https://myserver"
publishRetryMaxAttempts = 3
publishRetryInterval = 100
publishTimeout = 10_000
}
It can be helpful to proactively notify folks when a CI build fails via Slack. To help make that easier, the Projektor Gradle plugin has the option to write a formatted Slack message in a JSON file. This Slack message includes a direct link to the Projektor test report so users can quickly investigate test failures.
To use it, set the writeSlackMessageFile
parameter to true
.
By default, the Slack message is written to a file named projektor_failure_message.json
,
but you can specify your own file name by setting slackMessageFileName
Starting with plugin version 5.5.4
and server 3.5.1
, Projektor has the ability to publish and
visualize code coverage data as part of the Projektor report.
To include code coverage stats in your Projektor reports, first ensure you are using plugin version 5.5.4
or higher,
enable Jacoco in your build,
and include the jacocoTestReport
task with your build. That’s it.
The Projektor Gradle plugin will automatically configure, collect and upload the XML coverage reports from
each project in the build that uses Jacoco.
For an example Projektor report with coverage, check out https://projektorlive.herokuapp.com/tests/SUWSHGIRS6JP/coverage
Ironically, this example build shows that the code coverage of the coverage parsing module in Projektor is low. Need to work on that.
Update: Coverage for the parsing module looking better now: https://projektorlive.herokuapp.com/tests/0M7BEOCS9VJA/coverage
Kover is a recent code coverage tool from JetBrains for the Kotlin language: https://github.com/Kotlin/kotlinx-kover
Starting in Projektor Gradle plugin 7.8.2
Projektor supports gathering and publishing reports
from the Kover plugin when it is configured to use the Jacoco engine.
Projektor supports gathering Jacoco and Kover reports from different subprojects in a multi-project build. For example, you may have a multi-project build where some subprojects use Java so they gather code coverage with the Jacoco plugin and other Kotlin subprojects that use Kover for code coverage.
But don’t add both the Jacoco and Kover Gradle plugins in the same subproject, only use one or the other. Otherwise, you may get duplicate coverage reports in Projektor.
Key for using Kover coverage with Projektor:
7.8.2
or higherSome projects have separate test tasks, such as test
and integrationTest
.
Projektor will automatically collect coverage stats for all projects in a multi-project build,
but if your project has multiple test tasks in the same project you’ll need a bit of extra configuration
in your build.gradle
file to have Jacoco combine the coverage data from the different test tasks
before the coverage data is sent to the Projektor server:
// Combine the coverage data from the all test tasks into a single coverage report under the "jacocoTestReport" task
jacocoTestReport {
dependsOn tasks.withType(Test)
executionData { tasks.withType(Test)*.jacoco.destinationFile }
}
Starting with Gradle plugin 7.5.1
,
Projektor supports any and all code quality tools (linting, static analysis, etc.) that can output their results in text files.
To be able to see the code quality reports in your Projektor build,
pass the paths to the reports in the codeQualityReports
plugin config parameter.
For example, to collect the text reports from the ktlint
tool in a single-project Gradle build:
projektor {
serverUrl = "https://myserver"
codeQualityReports = [fileTree(dir: "build/reports/ktlint", include: "*.txt")]
}
Or to collect the reports from a Gradle multi-project build:
projektor {
serverUrl = "https://myserver"
codeQualityReports = [fileTree(dir: ".", include: "**/build/reports/ktlint/**/*.txt")]
}
Parameter | Type | Default | Description |
---|---|---|---|
serverUrl** | String |
null |
Projektor server URL to publish results to |
alwaysPublishInCI | boolean |
true |
Whether results are automatically published at the end of the build when running in CI |
publishOnLocalFailure | boolean |
true |
Whether results are automatically published at the end of the build if it fails when running locally |
alwaysPublish | boolean |
false |
Whether to always publish the results regardless of environment or outcome |
publishToken | String |
null |
Token to include in publish request to server (only needed when server has publish token set) |
additionalResultsDirs | List<String> |
[] |
Additional directories to include results from. Useful when you want to include results from a task that isn’t Test type |
attachments | List<FileTree> |
[] |
FileTrees to include as attachments to the test report and make available in the UI |
codeQualityReports | List<FileTree> |
[] |
Patterns for any code quality reports you want to include in your test report |
compressionEnabled | boolean |
true |
Whether to compress the test results with GZIP when sending them to the server |
publishRetryMaxAttempts | int |
3 |
Max number of attempts when retrying publish of results to server |
publishRetryInterval | long |
100 |
Amount to wait (in milliseconds) between retry attempts |
publishTimeout | long |
10_000 |
Timeout (in milliseconds) to send results to the server |
writeSlackMessageFile | boolean |
false |
Whether to write a Slack message file with a link to the Projektor test report |
slackMessageFileName | String |
projektor_failure_message.json |
Name of the Slack message file (if enabled) |
codeCoveragePublish | boolean |
true |
Whether to include code coverage data in the Projektor report (if the build has coverage enabled with the Jacoco plugin) |
gitMainBranchNames | List<String> |
["main", "master"] |
List of the mainline branches for this repo. Mainline branches are used when calculating things like current code coverage for the repo. |
** Required
Plugin version | Java version | Gradle version | Projektor server version |
---|---|---|---|
1.0.0 - 1.0.2 | 8+ | 5+ | 1.0.0+ |
1.0.3 | 8+ | 5+ | 1.0.6+ |
2.0.0 | 8+ | 5+ | 2.0.0+ |
3.0.0 | 8+ | 5+ | 2.0.0+ |
4.0.0 | 11+ | 5+ | 2.0.0+ |
5.0.0+ | 11+ | 5+ | 3.3.0+ |
5.1.0+ | 11+ | 5+ | 3.5.0+ |
7.0.0+ | 11+ | 5+ | 4.0.0+ |
8.0.0+ | 11+ | 7+ | 4.0.0+ |
8.3.0+ | 11+ | 7.6.1+ | 4.0.0+ |
9.0.0+ | 17+ | 7.6.1+ | 4.0.0+ |
In larger organizations it can be common to have base plugins that apply and configure a common set
of plugins used by each project. To apply the ProjektorPublishPlugin
this way from another plugin:
dependencies {
api "dev.projektor.publish:dev.projektor.publish.gradle.plugin:9.0.0"
}
class MyPlugin implements Plugin<Project> {
@Override
void apply(Project project) {
project.plugins.apply(ProjektorPublishPlugin)
project.projektor {
serverUrl = "https://myserver"
}
}
}