Setting Up the Gatling Plugin with Gradle: A Step-by-Step Guide
Written on
Chapter 1: Introduction to Gatling and Gradle
This guide focuses on how to establish a basic Java project that incorporates both Gradle and Gatling. If you already have a Gradle project in place, the following steps will still apply.
Section 1.1: Integrating the Gatling Plugin
To begin, add the Gatling plugin to your Gradle configuration. You can do this by including the following line:
plugins {
id 'io.gatling.gradle' version "MANUALLY_REPLACE_WITH_LATEST_VERSION"}
As of this writing, the most recent stable version is 3.10.3, so you would replace it as follows:
plugins {
id 'io.gatling.gradle' version "3.10.3"}
While there are various Gatling properties that can be configured, this guide will cover the essential setup similar to the quick start from Gatling tutorials.
gatling {
logLevel = 'WARN' // sets the logback root level
logHttp = 'NONE' // change to 'ALL' for all HTTP traffic in TRACE, or 'FAILURES' for DEBUG on failed traffic
enterprise {
}
}
Subsection 1.1.1: Setting the Correct Java Package Structure
To ensure your simulations are correctly placed within your project, the directory must follow the structure: src/gatling/java. If you have created a Gradle project or are attempting to integrate simulations using a different module structure, the Java class with Gatling dependencies may fail to compile.
Typically, when creating Java projects, the main package is formatted as src/main/java. Gatling Java files will not compile in this directory. After further research, I discovered that it is possible to alter the source directory in Gradle using sourceSets. For instance:
sourceSets {
gatling {
java.srcDirs = ["src/main/java/simulations"]}
}
However, this method did not compile successfully for me.
Section 1.2: Recommended Structure for Gatling
My recommendation is to stick with the default structure provided by the Gatling plugin. If everything is set up correctly, you should see the gatlingRun task available.
gradle gatlingRun
Here’s an example of a complete build.gradle file:
plugins {
id 'java'
id 'io.gatling.gradle' version '3.10.3'
}
group = 'org.example'
version = '1.0-SNAPSHOT'
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
repositories {
mavenCentral()}
gatling {
logLevel = 'WARN' // sets the logback root level
logHttp = 'NONE' // set to 'ALL' for all HTTP traffic in TRACE, 'FAILURES' for DEBUG on failed traffic
enterprise {
// Reference for Enterprise Cloud configurations
// Reference for Self-Hosted configurations
}
}
dependencies {
testImplementation platform('org.junit:junit-bom:5.9.1')
testImplementation 'org.junit.jupiter:junit-jupiter'
}
test {
useJUnitPlatform()}
This method of setup has proven successful, unlike the previous attempt with sourceSets.
Chapter 2: Next Steps and Resources
In the following sections, we'll explore how to configure a Docker container to run your Gatling tests efficiently.
For additional information, you can refer to the following resources: