ALTERNATIVE: Maven Plugin

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

The SeaLights Maven plugin is designed to wrap the entire SeaLights process into the Maven 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 pom.xml files of the Maven project are altered to incorporate the SeaLights plugin. This can be reversed using another CLI command.

SeaLights Maven plugin operates during specific Maven lifecyclearrow-up-right phases:

  • Build Scanner is executed during process-classes

  • Tests executed during the test phase are captured

Prerequisites

  • The following versions are the minimum required for integration with Maven test runners:

    • Surefire - version 2.8 and above, recommended is 2.22.2 and above.

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
}

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"

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

circle-exclamation
3

Add the plugin to your pom.xml

This step adds the SeaLights Maven plugin, configured with the items specified in your config file, to your project's pom.xml . To accomplish this, you will use the command java -jar sl-build-scanner.jar -pom -configfile <config-file-name> -workspacepath <path>

By doing this, you allow the SeaLights Maven 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 -pom \
-configFile /path/to/config/file.json \
-workspacepath "." 

What this command does:

  • Updates your pom.xml with the SeaLights Maven plugin and configuration details.

  • Creates a backup of your original pom.xml named pom.xml.slback

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

4

Execute your tests with Maven

Run your tests using the Maven command you normally do (typically, something like mvn clean install or mvn clean verify )

5

Restore your pom.xml (OPTIONAL)

circle-exclamation

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

Command:

java -jar sl-build-scanner.jar -restorePom -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?