Skip to content
Jon Austen edited this page Jun 30, 2015 · 21 revisions

#What is this plugin for? If you use gradle as your build tool, this plugin adds tasks to your build to create, edit, run jmeter tests and generate HTML reports from run results. You can include performance tests in your continuous integration workflow.

The newest release version is 1.3.4, you should always use the newest version possible. There are some known problems with older versions, see the known issues section for details. You should also try and use the newest version of jmeter possible, they include bug fixes and performance improvements.

#Getting Started

Adding the plugin to your project

To include this plugin in your build,

  • Add the plugin to your build.gradle
  • Add mavenCentral to your repositories
  • and finally add jmeter-gradle-plugin to your classpath

Here is a minimal example:

apply plugin: 'jmeter'
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "com.github.kulya:jmeter-gradle-plugin:1.3.4-2.13"
    }
}

Run gradle tasks to see the tasks added by the jmeter plugin under the Performance group

Note: versions earlier than 1.3.2 aren't available on maven central, and they use a different groupID. See also.

##Creating a test You can create a jmx file using jmeter elsewhere and simply drop the jmx file into $project.dir/src/test/jmeter. The plugin expects jmeter test files to be in this location by default. You can override the location by setting either the srcDir or the jmeterTestFiles properties. See Advanced Configuration for more details.

Alternatively, run gradle jmeterEditor. this will launch the jmeter GUI. Configure the test using the GUI and save the jmx file in the desired location. The GUI can also be used to edit existing test files

##Running your test The task to execute jmeter tests is gradle jmeterRun. jmeter.log is created in $project.dir/build/jmeter. You should look in this log for errors if the jmeter test fails. After a successful run, the results are stored in $project.dir/build/jmeter-test as a timestamped file. If reports are enabled, a HTML report for each run is created in the same folder as well.

Note: The jmeterEditor GUI can be used to run a test, GUI listeners can be very expensive though, and cause jmeter crash. Any sizeable jmeter tests should be run in non-GUI mode

##Clean Reports gradle jmeterCleanReport cleans up the jmeter-test folder.

##List Testplans gradle jmeterListTestPlan lists all the test plans in the default test plan location.

Note: This task does not currently list test plans set using the jmeterTestFiles property. See issue #37

#Advanced Configuration ##Using jmeter Plugins

To use extra jmeter-plugins, they need to be included in the dependencies section, as well as explicitly called out in the jmeterPluginJars property. Here is an example using jmeter plugins:

apply plugin: 'jmeter'
buildscript {
    ext {
        pluginsVersion = "1.2.1"
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "com.github.kulya:jmeter-gradle-plugin:1.3.4-2.13"
        classpath "org.codehaus.groovy:groovy-all:2.4.3"
        classpath group: 'kg.apc', name: 'jmeter-plugins-standard', version: pluginsVersion
        classpath group: 'kg.apc', name: 'jmeter-plugins-common', version: pluginsVersion
        classpath group: 'kg.apc', name: 'jmeter-plugins-extras', version: pluginsVersion
        classpath group: 'kg.apc', name: 'jmeter-plugins-extras-libs', version: pluginsVersion
        classpath group: 'kg.apc', name: 'jmeter-plugins-webdriver', version: pluginsVersion
    }
}
jmeterEditor.configure {
    maxHeapSize = "1200M"
    jmeterPluginJars = ["groovy-all",
                        "jmeter-plugins-standard",
                        "jmeter-plugins-common",
                        "jmeter-plugins-extras",
                        "jmeter-plugins-extras-libs", 
                        "jmeter-plugins-webdriver"]
}
jmeterRun.configure {
    jmeterUserProperties = []
    doFirst {
        if ( project.hasProperty('env') ) {
            def envName = project.property('env')
            println "Configuring for environment:" + envName
            jmeterUserPropertiesFiles = [file("props/" + envName + ".properties"),file("src/test/jmeter/user.properties")]               
        }
        if ( project.hasProperty('threads') {
            jmeterUserProperties << "threads=" + project.property('threads')
        }
    }
    jmeterTestFiles = [file("src/test/jmeter/API-Integration-Tests.jmx")]
    enableReports = true
    jmeterIgnoreFailure = false
    jmeterIgnoreError = false
}

##Adding additional java libraries ##JVM Options ##Proxy Configuration

##All Customizable Properties Standard Jmeter properties can be passed to this plugin with these Gradle properties:

Property Description
srcDir Directory with JMeter test files if you want include them all without strict order [ $project.dir/src/test/jmeter by default ]
includes JMeter files that you want to include at build
excludes JMeter files that you want to exclude from build
jmeterTestFiles List of JMeter test files (overrides srcDir)
reportDir Directory where you want to store your reports [ $project.buildDir/jmeter-report by default ]
enableReports Enable/Disable report generation [ true by default ]
jmeterIgnoreFailure Ignore JMeter failures [ false by default ]
jmeterIgnoreError Ignore JMeter errors [ false by default ]
reportPostfix Postfix that you want to use at report file [ -report.html by default ]
reportXslt Report XSLT location, if you want to use custom transformation
jmeterPropertyFile alternate properties file to be used with the -p jmeter option [ $projectDir/build/jmeter/jmeter.properties by default]
jmeterUserProperties List of JMeter user properties. For example: ["threads=2","loops=10"]
maxHeapSize Max heap size for jmeter process by default set to 512M. Support any walue that -Xmx property support
jmeterPluginJars specify plugin Jar files by module name; for example: ["groovy-all","jmeter-plugins.*"]. also requires adding matching dependency in the project dependencies.
jmeterEditFile JMeter file that you want to edit. This is used for jmeterEditor Task
jmeterUserPropertiesFiles List of user properties files

#Using version 1.3.1 or older The maven repo to use and the groupID are different for older versions. These versions also may not work with Gradle 2.0 and above.

apply plugin: 'jmeter'
buildscript {
	repositories {
		maven {
			url "http://repo.kulya.info/content/groups/public/"
		}
	}
	dependencies {
		classpath "org.veil.gradle.plugins:jmeter-gradle-plugin:1.2-2.6"
	}
}

#Known Issues version 1.3.4 See Issue #45 for HTML reports to work, you may have to add the additional property jmeter.save.saveservice.output_format=xml

See Issue #38 User is expected to define a jmeter.properties file in either /src/test/jmeter or using jmeterPropertyFile. Even a blank properties file is fine. If this is not provided the plugin will throw an error Could not read JMeter properties file

version 1.3.3 See Issue #41 If you use jmeter version 2.12 or 2.13, you will see error messages about missing dependencies. The workaround is to add exclusions to your dependencies.

version 1.3.2 See Issue #40 You will not see diagnostic error messages if jmeter launch fails.

version 1.3.1 and earlier do not work with gradle 2.0 and above. You will see an error Could not find method add() for arguments.... If you're using gradle above 2.0, please use a newer version of this plugin.

Clone this wiki locally