Recently I was working on JMeter test-plan. I had to write some custom functions which are not provided by JMeter. I somehow figured out implementation of custom-functions but soon faced the build problem. It took a little while to define the build.gradle to compile and generate jar file. Later I thought to share it here. If you are looking for JMeter plugin tutorial then you have to wait for a little while. If you are just looking for build.gradle for building your source code then please carry on.
Let’s start, first you need to have directory structure similar to, as shown below.

JMeter
├── build.gradle
└── src
    └── java
        └── com
            └── code4reference
                └── jmeter
                    └── functions
                        └── YourFunctionDefinition.java            

In this build.gradle file you need to take care of three things, First dependencies closure should be defined with compile 'org.apache.jmeter:ApacheJMeter_core:2.9' attribute, Second srcDir should point to the correct directory. In given gradle file, it is pointing to src/java since source code are present under this directory. Third Jar task should be defined. This task will create the jar file which you can place in /lib/ext directory.

apply plugin: 'java'

jar.baseName = 'C4RJMeter'  //custom jar file name.

repositories {
    mavenCentral()
}

dependencies {
    //This JMeter plugin source code build depends on JMeter2.9 version.
    compile 'org.apache.jmeter:ApacheJMeter_core:2.9'
    compile 'org.apache.jmeter:ApacheJMeter_components:2.9'
}

sourceSets {
   main {
      java {
         srcDir 'src/java'  //JMeter plugin source directory.
      }
   }
}

jar {
   manifest {
      attributes 'Implementation-Title': 'Code4Reference',
         'Built-By': System.getProperty('user.name'),
         'Built-Date': new Date(),
         'Built-JDK': System.getProperty('java.version')
   }
}

Once your source code and build.gradle are ready, you can run gradle jar. This command builds the jar file and keeps in the libs directory.

JMeter
└── build
    └── libs
        └── C4RJMeter.jar

Feel free to comment on the post or website. If you liked the post then please share it.

, ,
Trackback

no comment untill now

Add your comment now