# ALTERNATIVE: 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 lifecycle](https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#lifecycle-reference) 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

{% stepper %}
{% step %}

#### Download the SeaLights Java Agent

Download the latest version of the SeaLights Java Agent.&#x20;

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.zip>

Example CLI commands for downloading the SeaLights Java Agent:

```bash
# 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

#validate the agent version
echo "Sealights Java Agent version used is:" `cat sealights-java-version.txt`
```

{% hint style="info" %}
Instructions for downloading a specific version of the agent can be found [here](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/java-agent/default-usage-cli/downloading-the-java-agent#downloading-the-specific-agent-version-defined-in-customer-settings)
{% endhint %}

{% hint style="info" %}
Note: You will also need a valid SeaLights Agent Token, as explained in the [Prerequisites](/knowledgebase/phased-onboarding/java-onboarding-guide/getting-started/prerequisites.md)
{% endhint %}
{% endstep %}

{% step %}

#### 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:**

{% code overflow="wrap" %}

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

{% endcode %}

**Minimum Required Parameters for this configuration:**

* `tokenfile` - Your SeaLights [agent token](/knowledgebase/phased-onboarding/java-onboarding-guide/getting-started/prerequisites.md#access-credentials) 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[^1] 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](/knowledgebase/phased-onboarding/java-agent-parameter-reference/java-agent-configuration-parameters/java-plugin-configuration-parameters.md)

{% hint style="warning" %}
Do NOT name this configuration file `sealights.json` as this is a reserved file name used by the agent for internal override options.
{% endhint %}
{% endstep %}

{% step %}

#### 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:**

```bash
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.&#x20;
* 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.

{% endstep %}

{% step %}

#### 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` )
{% endstep %}

{% step %}

#### Restore your pom.xml (OPTIONAL)

{% hint style="warning" %}
IF your workspace is not reset for each run, you will need to restore them at the end of the run&#x20;
{% endhint %}

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

Command:

```bash
java -jar sl-build-scanner.jar -restorePom -workspacepath .
```

{% endstep %}
{% endstepper %}

#### 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

{% hint style="success" %}
If this test stage reflects coverage under your component, Phase 2 is complete!
{% endhint %}

***

### Next Steps

With advanced coverage analytics in place, you're ready to move on to [**Phase 3: Continuous Coverage**](/knowledgebase/phased-onboarding/java-onboarding-guide/phase-3-continuous-coverage.md). In Phase 3, you'll integrate SeaLights into your CI pipeline for continuous, up-to-date visibility into build coverage.

[^1]: Application Under Test


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sealights.io/knowledgebase/phased-onboarding/java-onboarding-guide/phase-2-advanced-coverage-analytics/using-supported-test-frameworks/alternative-maven-plugin.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
