1

I wrote a Maven application that I want to use in my Jmeter BeanShell script. The Maven application is using Google Guice 4.2.2 for dependecy injection and it is calling an API at the end (Code needs to perform some other operations before calling the API and that's why I am not using the JMeter Plugin). I am creating the uber JAR (Fat JAR) with maven-shade-plugin. When I run the Jar from the command line the application run successfully!

However, When I load the JAR in my Jmeter test plan and call my application main method in the Jmeter BeanShell I am getting the following error:

java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;)V
    at com.google.inject.Key.ensureRetainedAtRuntime(Key.java:341) ~[load-testing.jar:?]
    .
    .
    .

Now lots of other threads mentioned that this can be because of older Google Guava version (20.x older) but from the dependency tree I see the Guava version is 25.1-android and I can run my JAR successfully from the command line!!

Also, I list the classes in the Uber JAR by running jar -tf command and I can see that the com.google.common.base.Preconditions class is there.

I would appreciate it if someone can shed some light on this matter and help me to resolve this?

Saikat
  • 14,222
  • 20
  • 104
  • 125
click
  • 447
  • 1
  • 7
  • 25
  • I think I found the problem. I think my Guava is conflicting with Jmeter Guava version. I just downloaded the ApacheJmeter_core v5.1.1 and observed thta it is leveraging a guava version 17.0 that can usually cause this exception. Guava version should be usually 20.0.x > – click Nov 25 '19 at 21:51

3 Answers3

0

It seems that your fat-jar contains multiple versions of Guava (which may be caused by the shade-plugin).

Make sure to lock it to single version by using Mavens dependency management in each maven module. (https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Management)

bastian
  • 106
  • 2
  • I am not sure about that because when I run the JAR from the terminal it is successful. Another test that I perform was placing a jar in a simple maven app and call my main class which was also successful – click Nov 21 '19 at 03:23
0

The Beanshell itself might be a problem, since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting, the reasons are in:

  • Groovy is more "modern" language which supports all modern Java features while with Beanshell you're stuck at Java 1.5 language level (no lambdas, no generics, no multi-catch etc.)
  • Groovy performance is much better comparing to Beanshell cause Grooovy engine implements Compilable interface and is capable of caching compiled scripts providing performance very close to native Java code
  • Groovy provides a lot of enhancements on top of standard Java SDK

Check out Apache Groovy - Why and How You Should Use It article for more details.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Thanks for the info, I have already tested this with the JSR233 and Groovy 2.4.16 however a same issue is happening – click Nov 25 '19 at 19:43
0

I have finally cofirmed my comment. The problem was my JAR Guava version was conflicting with Jmeter Guava version (which is 17.0) and Jmeter for some reason is picking up its own Guava version, after downgrading Guice version to 3.0 which does not depend on guava, I successfully ran my JAR through Jmeter.

There is still a mystery on why Jmeter is overriding my JAR Guava version with its own. I will create a ticket with Jmeter in order to find more about this mystery but this change solved my problem

click
  • 447
  • 1
  • 7
  • 25