Search code examples
mavenapache-kafkajmeterintegration

Error when trying to execute existing Jmeter script in Maven project that is written in Jsr223 sampler in groovy


I have an existing jmeter (5.5 version) script written in Jsr223 sampler using Groovy (3.0.11) language. I created a new maven project and under the src/test folder, I created a new directory called jmeter and imported the test.jmx file.I updated my pom.xml file to include dependencies . I am using JDK 17. When I run the project, I am able to see that it reads test.jmxl file but throws an error saying this :-

2023-03-29 14:54:19,906 ERROR o.a.j.JMeter: Uncaught exception in thread Thread[Regular Thread Group 1-1,5,main] org.codehaus.groovy.GroovyBugError: BUG! exception in phase 'semantic analysis' in source unit 'Script1.groovy' Unsupported class file major version 61 at org.codehaus.groovy.control.CompilationUnit$ISourceUnitOperation.doPhaseOperation(CompilationUnit.java:905) ~[groovy-3.0.7.jar:3.0.7]

Here is my pom.xml file : -


<?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>retry44</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
        <dependencies>
            <dependency>
                <groupId>org.apache.kafka</groupId>
                <artifactId>kafka-clients</artifactId>
                <version>3.1.1</version>
            </dependency>
            <dependency>
                <groupId>org.apache.jmeter</groupId>
                <artifactId>ApacheJMeter_core</artifactId>
                <version>5.5</version>
            </dependency>
            <dependency>
                <groupId>org.apache.jmeter</groupId>
                <artifactId>ApacheJMeter_java</artifactId>
                <version>5.5</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-all -->
            <dependency>
                <groupId>org.codehaus.groovy</groupId>
                <artifactId>groovy-all</artifactId>
                <version>3.0.11</version>
                <type>pom</type>
            </dependency>

        </dependencies>

        <build>
            <plugins>
                <plugin>
                    <groupId>com.lazerycode.jmeter</groupId>
                    <artifactId>jmeter-maven-plugin</artifactId>
                    <version>3.4.0</version>
                    <executions>
                        <!-- Generate JMeter configuration -->
                        <execution>
                            <id>configuration</id>
                            <goals>
                                <goal>configure</goal>
                            </goals>
                        </execution>
                        <!-- Run JMeter tests -->
                        <execution>
                            <id>jmeter-tests</id>
                            <goals>
                                <goal>jmeter</goal>
                            </goals>
                        </execution>
                        <!-- Fail build on errors in test -->
                        <execution>
                            <id>jmeter-check-results</id>
                            <goals>
                                <goal>results</goal>
                            </goals>
                        </execution>
                    </executions>

                </plugin>
            </plugins>

        </build>

</project>

I am trying to run an existing Jmeter script using Maven project. I was expecting that the code would read the .jmx file successfully and perform necessary actions


Solution

  • Upgrade JMeter Maven Plugin to version 3.7.0 and it will resolve your issue

    Also if you need to specify any dependencies and/or external libraries it needs to be done a little bit differently, check out How to Use the JMeter Maven Plugin