> For the complete documentation index, see [llms.txt](https://docs.sealights.io/knowledgebase/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sealights.io/knowledgebase/phased-onboarding/java-onboarding-guide/phase-3-continuous-coverage/alternative-maven-plugin.md).

# ALTERNATIVE: Maven Plugin

{% hint style="warning" %}
**Prerequisite:** You have completed [Phase 2: Advanced Coverage Analytics](/knowledgebase/phased-onboarding/java-onboarding-guide/phase-2-advanced-coverage-analytics.md)
{% endhint %}

The **SeaLights Maven plugin** is designed to wrap the entire process (Build Scan + Test Listener functions) 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

The option `IncludeResources` will add the Sealights' text files (`sltoken` and `buildSessionId`) to the `target/classes` folder during `process-classes`. These two text files will be added automatically to the artifact (`.jar`, `.war`,...) during the package phase as they're already placed in the relevant folder.

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

{% hint style="info" %}
Prerequisite: Your application is already set up to run with SeaLights as a `javaagent`, per the instructions in previous phases.
{% endhint %}

{% stepper %}
{% step %}

#### Download the SeaLights Java Agent

{% hint style="info" %}
You have previously downloaded the SeaLights Java agent for use by your component at runtime (adding it as a `javaagent` in Phase 1), and on your Test Runners (Phase 2). Now you will need the SeaLights Java Agent to be available during the build step in your CI pipeline.
{% endhint %}

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`

**Minimum Required Parameters for this configuration:**

* `tokenfile` - Path to the [**agent token file**](/knowledgebase/phased-onboarding/java-onboarding-guide/getting-started/prerequisites.md). Note: The token can also be placed in a file named `sltoken.txt` in the same directory as the agent. In that case, this parameter is not required.
* `appname` - The **name of your component**. This name will appear in the SeaLights dashboard and reports. This can be any name that represents your component.
* `branchname` - Git branch name (defaults to "main" if not specified)
* `buildname` - A **unique identifier** that represents the current build of your component — for example, the CI build number, a timestamp, or a custom name (as long as it is unique).
* `packagesIncluded` - A comma-separated list of packages composing the application. Specifies which Java packages SeaLights should monitor for coverage. By default, SeaLights may analyze all packages, but explicitly setting this improves performance.
* `executionType` - Set to "full"&#x20;

Additional Recommended Parameters:

* `createBuildSessionId` - set to true
* `recursive` - set to true

**Example Configuration File:**

{% code overflow="wrap" %}

```json
{
  "executionType": "full",
  "tokenFile": "sltoken.txt",
  "createBuildSessionId": true,
  "appName": "<component-name>",
  "branchName": "<branch-name>",
  "buildName": "<build-name>",
  "packagesIncluded": "*com.example.*",
  "recursive": true,
}
```

{% endcode %}

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

By doing this, you allow the SeaLights Maven plugin to add the necessary SeaLights configuration to automatically complete the configuration, BSID generation, and build scan (steps 2-3 if you were using the implementation steps) as a part of your Maven build.

**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 <config-file-name> -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 %}

#### Build your artifact

The next step is to simply build your artifact as you normally would (typically with something like `mvn clean install` or `mvn clean verify`).&#x20;

The SeaLights Maven plugin was added to your pom file, so when you run your build, it is automatically packaged up as part of your artifact.
{% 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. This is generally not a concern if you are implementing this in a CI pipeline.
{% endhint %}

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

**Command:**

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

{% endstep %}
{% endstepper %}

## Verification

To confirm that Phase 3 was successful:

1. **Check the console output** — Look for messages confirming successful agent startup and scan completion.
2. Visit the SeaLights Dashboard — Verify that:
   1. Your component's build name appears with the name you have given it in the configuration file
   2. Coverage data is correctly reflected in the test stage

***

## Next Steps

With Continuous Coverage in your CI now in place, you can move to [**Phase 4: Test Impact Analysis**](/knowledgebase/phased-onboarding/java-onboarding-guide/phase-4-test-impact-analysis-tia.md). In Phase 4, you'll begin using TIA to execute the smallest subset of tests — without compromising quality.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.sealights.io/knowledgebase/phased-onboarding/java-onboarding-guide/phase-3-continuous-coverage/alternative-maven-plugin.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
