Gatling Maven Plugin
The Maven plugin allows you to run Gatling tests from the command line, without the bundle, as well as to package your simulations for Gatling Enterprise Edition.
Using this plugin, Gatling can be launched when building your project, for example with your favorite Continuous Integration (CI) solution. This plugin can also be used to package your Gatling project to run it on Gatling Enterprise Edition.
This documentation assumes that you have Maven installed on your machine and hence uses the standard Maven command format (for example mvn gatling:test). If you prefer to use the Maven wrapper that downloads and installs Maven on-the-fly, its equivalent commands follow the format:
./mvnw gatling:<command>
mvnw.cmd gatling:<command>
Where <command> is the gatling goal (for example test, recorder, enterprisePackage, enterpriseStart).
Versions
Check out available versions on Maven Central.
Beware that milestones (M versions) are not documented for Community Edition users and are only released for Gatling Enterprise Edition customers.
Setup
Cloning or downloading one of our demo projects on GitHub is definitely the fastest way to get started:
If you prefer to manually configure your Maven project rather than clone one of our samples, you need to add the following to your pom.xml:
<dependencies>
<dependency>
<groupId>io.gatling.highcharts</groupId>
<artifactId>gatling-charts-highcharts</artifactId>
<version>MANUALLY_REPLACE_WITH_LATEST_VERSION</version>
<scope>test</scope>
</dependency>
</dependencies>
<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
<version>MANUALLY_REPLACE_WITH_LATEST_VERSION</version>
</plugin>
scala-maven-plugin when using Gatling with Simulations written in Scala. Please check the pom.xml of the demo project for Maven and Scala mentioned above for complete configuration.Configuration
The plugin supports many configuration options, eg:
<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
<version>MANUALLY_REPLACE_WITH_LATEST_VERSION</version>
<configuration>
<simulationClass>foo.Bar</simulationClass>
</configuration>
</plugin>
See each goal’s section below for the relevant configuration options.
Usage
Running your simulations
You can directly launch the gatling-maven-plugin with the test goal:
mvn gatling:test
Use mvn gatling:help -Ddetail=true -Dgoal=test to print the description of all the available configuration options on
the test goal.
The gatling:test goal runs in interactive mode and suggests the simulation class to launch unless:
- there’s only one simulation available,
- or the Simulation class is forced with the
-Dgatling.simulationClass=<FullyQualifiedClassName>Java System Property, - or the non-interactive mode is forced, in which case the task will fail if there is more than 1 simulation available,
- or it’s in batch mode (
-BMaven option), in which case the task will fail if there is more than 1 simulation available, - or the
CIenv var is set totrue, in which case the task will fail if there is more than 1 simulation available.
Running the Gatling Recorder
You can launch the Gatling Recorder:
mvn gatling:recorder
Use gatling:help -Ddetail=true -Dgoal=recorder to print the description of all the available configuration options
on the recorder goal.
Running your simulations on Gatling Enterprise Edition
Prerequisites
You need to configure an an API token for most of the actions between the CLI and Gatling Enterprise Edition.
Configure role on expected teams.Since you probably don’t want to include you secret token in your source code, you can configure it using either:
- the
GATLING_ENTERPRISE_API_TOKENenvironment variable - the
gatling.enterprise.apiTokenJava System property
If really needed, you can also configure it in your pom.xml:
<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
<version>${gatling-maven-plugin.version}</version>
<configuration>
<apiToken>YOUR_API_TOKEN</apiToken>
</configuration>
</plugin>
Deploying on Gatling Enterprise Edition
With gatling:enterpriseDeploy command, you can:
- Create, update and upload packages
- Create and update simulations
This command automatically checks your simulation project and performs the deployment according to your configuration.
By default, enterpriseDeploy searches for the package descriptor in .gatling/package.conf.
However, you can target a different filename in .gatling by using the following command:
mvn gatling:enterpriseDeploy -Dgatling.enterprise.packageDescriptorFilename="<file name>"
You can run this command without any configuration to try it.
Check the Configuration as Code documentation for the complete reference and advanced usage.
Start your simulations on Gatling Enterprise Edition
You can, using the gatling:enterpriseStart command:
- Automatically deploy your package and associated simulations
- Start a deployed simulation
By default, the Gatling plugin prompts the user to choose a simulation to start from amongst the deployed simulations. However, users can also specify the simulation name directly to bypass the prompt using the following command:
mvn gatling:enterpriseStart -Dgatling.enterprise.simulationName="<simulation name>"
Replace <simulation name> with the desired name of the simulation you want to start.
If you are on a CI environment, you don’t want to handle interaction with the plugin.
Most CI tools define the CI environment variable, used by the Gatling plugin to disable interactions and run in headless mode.
It’s also possible to disable interactions by running Maven in batch mode.
Here are additional options for this command:
-Dgatling.enterprise.waitForRunEnd=true: Enables the command to wait until the run finishes and fail if there are assertion failures.-Dgatling.enterprise.runTitle=<title>: Allows setting a title for your run reports.-Dgatling.enterprise.runDescription=<description>: Allows setting a description for your run reports summary.
Upload a package manually
Packaging
You can directly package your simulations for Gatling Enterprise Edition using:
mvn gatling:enterprisePackage
This will generate the target/<artifactId>-<version>-shaded.jar package which you can then
upload to the Cloud.
Private packages
Configure the Control Plane URL:
<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
<version>${gatling-maven-plugin.version}</version>
<configuration>
<controlPlaneUrl>YOUR_CONTROL_PLANE_URL</controlPlaneUrl>
</configuration>
</plugin>
Once configured, your private package can be created and uploaded using the deploy command.
Integrating with the Maven lifecycle
The plugin’s goals can also be bound to the Maven lifecycle phases by configuring an execution block in the plugin configuration:
<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
<version>MANUALLY_REPLACE_WITH_LATEST_VERSION</version>
<executions>
<execution>
<goals>
<goal>test</goal>
<goal>enterprisePackage</goal>
</goals>
</execution>
</executions>
</plugin>
By default:
testwill be bound to theintegration-testphase, e.g. it will be triggered bymvn integration-testormvn verifyenterprisePackagewill be bound to thepackagephase, e.g. it will be triggered bymvn package
Overriding the logback.xml file
You can either have a logback-test.xml that has precedence over the embedded logback.xml file, or add a JVM option -Dlogback.configurationFile=myFilePath.
Sources
If you’re interested in contributing, you can find the gatling-maven-plugin sources on GitHub.