ALTERNATIVE: Gradle Plugin

Capture coverage on a supported test framework using the SeaLights Gradle Plugin

The SeaLights Gradle plugin is designed to wrap the entire SeaLights process into the Gradle lifecycle, allowing seamless integration with the build tool.

This solution uses the build scanner.jar file as well as a JSON configuration file. Once the jar is executed specifying the configuration file, the build.gradle files of the Gradle project are altered to incorporate the SeaLights plugin. This can be reversed using another CLI command.

Prerequisites

  • Automatic integration of Sealights settings into your build.gradle script is currently supported only for Groovy language.

Implementation Steps

1

Download the SeaLights Java Agent

Download the latest version of the SeaLights Java Agent.

There are two agent files

  • Build Scanner - sl-build-scanner.jar

  • Test Listener - sl-test-listener.jar

These agent files can be downloaded from: https://agents.sealights.co/sealights-java/sealights-java-latest.ziparrow-up-right

Example CLI commands for downloading the SeaLights Java Agent:

# Download the latest Java agent
wget -nv https://agents.sealights.co/sealights-java/sealights-java-latest.zip

# Extract the agent
unzip -oq sealights-java-latest.zip
circle-info

Instructions for downloading a specific version of the agent can be found herearrow-up-right

circle-info

Note: You will also need a valid SeaLights Agent Token, as explained in the Prerequisites

2

Create a configuration file

This step allows you to set any necessary configuration in a dedicated configuration file, which will be used when adding the SeaLights Maven Plugin details to your project's pom.xml

Example Configuration File:

{
  "tokenFile": "./sltoken.txt",
  "executionType": "testsonly",
  "testStage": "Functional Tests",
  "labId": "<test-env-id>",
  "runFunctionalTests": true,
  "createBuildSessionId": false,
}

Minimum Required Parameters for this configuration:

  • tokenfile - Your SeaLights agent token or path to token file

  • executionType - Set to "testsonly"

  • testStage - A label for the type of tests being run (e.g., "Functional Tests", "Integration Tests", "E2E Tests"). This will be used when displaying the test results in your SeaLights reports.

  • labId - A unique name representing the environment in which your AUT was deployed (and against which you are testing). This MUST match the Lab ID from Phase 1.

  • runFunctionalTests - Set to true

  • createBuildSessionId - Set to false

Additional optional parameters may be found here: Java Plugin Configuration Parameters

circle-exclamation
triangle-exclamation
3

Add the plugin to your build.gradle

This step adds the SeaLights Gradle plugin, configured with the items specified in your config file, to your project's build.gradle . To accomplish this, you will use the command java -jar sl-build-scanner.jar -gradle -configfile <config-file-name> -workspacepath <path> This will create a sealights.gradle script with all the configuration taken from the JSON config file and append a reference to it in build.gradle.

By doing this, you allow the SeaLights Gradle plugin to add the necessary SeaLights configuration to run with your test runner, without needing to update the JVM options at runtime.

Minimum Required Parameters for this command:

  • -configFile - Path to the file containing the JSON configuration you created in Step 2.

  • -workspacepath - The base path to the location of the pom.xml files to update

Command:

java -jar sl-build-scanner.jar -gradle \
-configFile /path/to/config/file.json \
-workspacepath "." 

What this command does:

  • Creates a sealights.gradle script with all of the configuration taken from the JSON config file

  • Updates your build.gradle with the SeaLights Gradle plugin and reference to the sealights.gradle script.

  • Creates a backup of your original build.gradle named build.gradle.slback

Output: In the console, you will see [Sealights Build Scanner] - Successfully finished SeaLights integration if the command was successful.

4

Execute your tests with Gradle

Run your tests using the Gradle command you normally do (typically, something like gradle clean test )

5

Restore your gradle.build (OPTIONAL)

circle-exclamation

Use the -restore flag to restore your pom.xml to its original content.

Command:

java -jar sl-build-scanner.jar -restoreGradle -workspacepath .

What Happens When Your Test Runner Starts?

The SeaLights agent rides along with your test runner to send metadata about the tests you're running to the SeaLights Backend. After your test execution is completed, SeaLights will automatically show you the percentage of code covered by this test run.

Verification

To confirm Phase 2 (ALTERNATIVE) was successful:

  1. Check the console output — Look for messages confirming successful agent startup and scan completion.

  2. Visit the SeaLights Dashboard — Verify that:

    • Your new test stage appears in the dashboard under your component

    • Coverage data begins appearing under the new test stage

circle-check

Next Steps

With advanced coverage analytics in place, you're ready to move on to Phase 3: Continuous Coverage. In Phase 3, you'll integrate SeaLights into your CI pipeline for continuous, up-to-date visibility into build coverage.

Last updated

Was this helpful?