Gradle with Jmeter Integeration

Pre requisite:
You should have a sample project that can be built with Gradle Command.

There is well-known plugin available for Gradle is Kulya. Here is the URL:

Step 1:

Add below snippet to your build.gradle file located in your project:

Below is the screen shot of above:

Step 2:

From the command line go to your project root folder:

If you want to cross verify whether plugin correctly setup, you can check by putting“Check point”) in your file.

Advanced Configuration:

In most cases, you will need to pass user defined variables to jmeter which are known at run time only.

Lets first load the jmeter script file that is .jmx file.

For that one can make use of jmeterTestFiles parameter.

So now, put your script is in your project directory, and now if you enter your gradle jmeterRun , it will load your jmeter scripts.

Hope you are able to run your first script.

If yes, than check your build directory, it will have jmeter folder and jmeter_report. Explore it. It will have all property file and logs in jmeter folder. Jmeter_report will have the final output in form of xml and the html report for fancy user friendly display. Go impress your boss.

Below is the screen shot of my project directory:

The most useful case is to pass jmeter user defined variable through gradle. For example the basic one would be the Server ip and Port number.

It is very basic requirement of jmeter script to be flexible enough to run on any environment. So, to run jmeter script  many people needs user defined variable to pass  along with the jmeter command line like below:

Above command will run the jmx file setting the value SERVER and PORT in jmx file.

To achieve the same with the gradle, you can pass any parameter same as Jmeter command line with a small change. It uses –D instead of –J. On the eclipse side in your file, you can catch those parameter by

System.getProperty(‘Key’, ‘default value in not provided’) .

So by above command you can simple catch any parameter that you want to pass to jmeter.

Now how do you pass these parameters to jmeter. For the given plugin, you can make use of jmeterUserProperties file.

You can add as many parameters as you want to add in array and assign it to

jmeterUserProperties variable as shown below

To sum up every thing below is the generalized snippet in a little more clean way:

Hope you able to run everything smoothly. Below is the screen shot of terminal.


Please ignore the grammatical mistakes.

Leave a Reply

Your email address will not be published. Required fields are marked *