Reputation: 21524
I want to run the JMeter GUI from my Gradle script, so that I can carefully control version and environment factors and so there's no pre-requisite setup stuff for my local developer machine build1.
My JMeter's build.gradle (part of a multi-project build):
plugins{
id 'base'
id 'java'
}
repositories {
jcenter()
}
dependencies {
compile 'org.apache.jmeter:ApacheJMeter:4.0'
}
task jmeterGui(type: JavaExec){
workingDir = "$project.buildDir/jmeter-working-dir"
classpath = sourceSets.main.runtimeClasspath
main = "org.apache.jmeter.NewDriver"
doFirst{
println "running Jmeter from Gradle"
mkdir workingDir
}
}
This results in an error:
> Task :functional-test:jmeterGui
java.lang.Throwable: Could not access <source root>\functional-test\build\lib
at org.apache.jmeter.NewDriver.<clinit>(NewDriver.java:102)
java.lang.Throwable: Could not access <source root>\functional-test\build\lib\ext
at org.apache.jmeter.NewDriver.<clinit>(NewDriver.java:102)
java.lang.Throwable: Could not access <source root>\functional-test\build\lib\junit
at org.apache.jmeter.NewDriver.<clinit>(NewDriver.java:102)
java.lang.ClassNotFoundException: org.apache.jmeter.JMeter
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.apache.jmeter.NewDriver.main(NewDriver.java:242)
JMeter home directory was detected as: <source root>\functional-test\build
I can't find anything in the JMeter user manual for this. Is it doable?
EDIT: This GUI that I launch is only intended for editing test plans. I use Redline13 for running the actual load tests.
1 Currenly in my build everything is strictly version controlled and part of my Gradle build. This includes NodeJS, NPM and Terraform. Literally the only setup pre-requisite is a Java 8 JDK. I want to continue that approach with JMeter.
Upvotes: 1
Views: 1211
Reputation: 21524
Here is my best current attempt at running the JMeter GUI from Gradle. Note that the GUI starts, but is pretty much non-functional (can't even open a test plan).
dependencies {
// using the runtime classpath instead of compile in order to avoid
// downloading all these and their deps in places where we never intend
// to run the JMeter GUI (continuous build environments, etc.)
runtime 'org.apache.jmeter:ApacheJMeter:4.0'
runtime 'org.apache.jmeter:jorphan:4.0'
runtime 'org.apache.jmeter:ApacheJMeter_core:4.0'
runtime 'org.apache.jmeter:ApacheJMeter_components:4.0'
runtime 'org.apache.jmeter:ApacheJMeter_config:4.0'
runtime 'org.apache.jmeter:ApacheJMeter_functions:4.0'
runtime 'org.apache.jmeter:ApacheJMeter_java:4.0'
runtime 'org.apache.jmeter:ApacheJMeter_http:4.0'
runtime 'org.apache.jmeter:ApacheJMeter_tcp:4.0'
runtime 'org.apache.jmeter:ApacheJMeter_parent:4.0'
}
task launchJmeterGui(type: JavaExec){
description = "Launch the JMeter GUI for editin test plans"
workingDir = "$project.buildDir/jmeter-working-dir"
classpath = sourceSets.main.runtimeClasspath
// This is the main class that the jmeter.bat file invokes.
// I think this thing is specifically intended to be invoked from a batch/
// shell script and is not intended to be invoked like this.
main = "org.apache.jmeter.NewDriver"
// I think this controls where the log file goes, not sure.
args "--homedir=${workingDir.absolutePath}"
doFirst{
println "Launching Jmeter from Gradle"
// log file ends up in here
mkdir workingDir
// I don't put anything in here, but there will be errors in the console
// output if they don't exist. I think this is where the darcula jar
// needs to be in order to work?
mkdir "$buildDir/lib"
mkdir "$buildDir/lib/ext"
mkdir "$buildDir/lib/junit"
// Copied into the source tree from a JMeter 4.0 install.
// Will run without these files but will print errors to console/log file.
// I'm happy to put these under source control, that makes sense to me.
project.copy {
from "src/test/resources/jmeter.properties"
from "src/test/resources/log4j2.xml"
into "$buildDir/bin"
}
}
}
Upvotes: 1
Reputation: 168157
You are adding a compile-time dependency while trying to use in in the runtime.
Change this line:
compile 'org.apache.jmeter:ApacheJMeter:4.0'
to this one:
runtime group: 'org.apache.jmeter', name: 'ApacheJMeter', version: '4.0'
and this should resolve your error.
References:
Be aware that JMeter GUI is for tests development and debugging, when it comes to load test execution it is recommended to run JMeter in non-GUI mode so I would strongly recommend reconsidering this "GUI" step.
Upvotes: 0