Create executable jar from maven gatling project

I want to create an executable JAR from my maven gatling project to be able to execute a performance test on any remote machine without an internet connection.
I create the project via https://gatling.io/docs/current/extensions/maven_archetype#maven-archetype (in IntelliJ).

My project structure looks like this:

src/
test/
resources/
bodies/ (contains json/xml/etc)
data/ (contains pdf/csv)

gatling.conf

logback.xml

recorder.conf

scala/ (I created the simulations modular)
config/
flows/

functions/

scenarios/

simulations/

transactions/
Engine.scala

IDEPathHelper.scala

Recorder

My POM file looks like:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.example</groupId>
  <artifactId>Gatling_default</artifactId>
  <version>1.0-SNAPSHOT</version>

  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <encoding>UTF-8</encoding>

    <gatling.version>3.3.1</gatling.version>
    <gatling-maven-plugin.version>3.0.5</gatling-maven-plugin.version>
    <scala-maven-plugin.version>4.3.0</scala-maven-plugin.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>io.gatling.highcharts</groupId>
      <artifactId>gatling-charts-highcharts</artifactId>
      <version>${gatling.version}</version>
    </dependency>
    <dependency>
      <groupId>io.gatling</groupId>
      <artifactId>gatling-app</artifactId>
      <version>${gatling.version}</version>
    </dependency>
    <dependency>
      <groupId>io.gatling</groupId>
      <artifactId>gatling-recorder</artifactId>
      <version>${gatling.version}</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>net.alchim31.maven</groupId>
        <artifactId>scala-maven-plugin</artifactId>
        <version>${scala-maven-plugin.version}</version>
        <configuration>
          <args>
            <arg>-target:jvm-1.8</arg>
            <arg>-deprecation</arg>
            <arg>-feature</arg>
            <arg>-unchecked</arg>
            <arg>-language:implicitConversions</arg>
            <arg>-language:postfixOps</arg>
          </args>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>testCompile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>io.gatling</groupId>
        <artifactId>gatling-maven-plugin</artifactId>
        <version>${gatling-maven-plugin.version}</version>
        <configuration><disableCompiler>true</disableCompiler></configuration>
      </plugin>
    </plugins>
  </build>
</project>

I would really appreciate the help!

I was able to resolve this myself.

What I did was:

  • changing /src/test to /src/main
  • and I made changes to the POM.
  • I added the maven shade plugin.
  • I changed the part for gatling maven plugin (so the Engine that comes with the maven archetype keeps working; I also needed to make some changes in IDEPathHelper for this)

The POM I work with now:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.example</groupId>
  <artifactId>Gatling_default</artifactId>
  <version>3.3.1</version>
  <packaging>jar</packaging>

  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <encoding>UTF-8</encoding>

    <gatling.version>${project.version}</gatling.version>
    <gatling-maven-plugin.version>3.0.5</gatling-maven-plugin.version>
    <maven-shade-plugin.version>3.2.1</maven-shade-plugin.version>
    <scala-maven-plugin.version>4.3.1</scala-maven-plugin.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>io.gatling.highcharts</groupId>
      <artifactId>gatling-charts-highcharts</artifactId>
      <version>${gatling.version}</version>
    </dependency>
    <dependency>
      <groupId>io.gatling</groupId>
      <artifactId>gatling-app</artifactId>
      <version>${gatling.version}</version>
    </dependency>
    <dependency>
      <groupId>io.gatling</groupId>
      <artifactId>gatling-recorder</artifactId>
      <version>${gatling.version}</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>net.alchim31.maven</groupId>
        <artifactId>scala-maven-plugin</artifactId>
        <version>${scala-maven-plugin.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
            </goals>
            <configuration>
              <jvmArgs><jvmArg>-Xss100M</jvmArg></jvmArgs>
              <args>
                <arg>-target:jvm-1.8</arg>
                <arg>-deprecation</arg>
                <arg>-feature</arg>
                <arg>-unchecked</arg>
                <arg>-language:implicitConversions</arg>
                <arg>-language:postfixOps</arg>
              </args>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>${maven-shade-plugin.version}</version>
        <configuration>
          <filters>
            <filter>
              <artifact>*:*</artifact>
              <excludes>
                <exclude>META-INF/*.DSA</exclude>
                <exclude>META-INF/*.SF</exclude>
                <exclude>META-INF/*.RSA</exclude>
              </excludes>
            </filter>
          </filters>
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <mainClass>io.gatling.app.Gatling</mainClass>
                </transformer>
              </transformers>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>io.gatling</groupId>
        <artifactId>gatling-maven-plugin</artifactId>
        <version>${gatling-maven-plugin.version}</version>
        <configuration>
          <simulationsFolder>${project.basedir}\src\main\scala</simulationsFolder>
          <resourcesFolder>${project.basedir}\src\main\resources</resourcesFolder>
          <configFolder>${project.basedir}\src\main\resources</configFolder>
          <resultsFolder>${project.basedir}\target</resultsFolder>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Via mvn clean install, the jar is created.
An example command to run a test with the jar:

java -jar Gatling_default-3.3.1.jar -s simulations.simulation1

Have at look at this example : https://github.com/jecklgamis/gatling-test-example

This is working for me also.

Thank you.