在学习了几个在线教程之后,我尝试在我的gradle构建中包含一些负载测试。我在执行gradle loadTest时遇到了这个错误。我使用的是Java 12(在build.gradle中配置了sourceCompatibility 11)
相关插件:
apply plugin: "scala"
implementation('org.scala-lang:scala-library:2.13.0')
testCompile("io.gatling.highcharts:gatling-charts-highcharts:3.2.1")
分级任务:
task loadTest(type: JavaExec) {
dependsOn testClasses
description = "load test with Gatling"
group = "Load Test"
classpath = sourceSets.test.runtimeClasspath
main = "io.gatling.app.Gatling"
args = [
"--simulation", "com.skios.ms.authentication.test.MainSimulation",
"--results-folder", "${buildDir}/gatling-results",
"--bodies-folder", sourceSets.test.resources.srcDirs.toList().first().toString() + "/gatling/bodies",
]
}
测试类别:
package com.skios.ms.authentication.test
import scala.language.postfixOps
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
class MainSimulation extends Simulation {
val httpConf = http.baseUrl("https://MYAPI.COM/api/v1")
val scn = scenario("Sample")
.exec(http("request1")
.get("/authentication/get-token"))
.pause(100)
setUp(scn.inject(rampUsers(20) during (5 seconds)).protocols(httpConf))
}
分级结果:
Starting a Gradle Daemon (subsequent builds will be faster)
> Task :compileTestScala
Pruning sources from previous analysis, due to incompatible CompileSetup.
> Task :loadTest FAILED
Exception in thread "main" java.lang.NoClassDefFoundError: scala/Serializable
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:151)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:802)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:700)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:623)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at com.typesafe.scalalogging.StrictLogging.$init$(Logging.scala:39)
at io.gatling.app.Gatling$.<init>(Gatling.scala:35)
at io.gatling.app.Gatling$.<clinit>(Gatling.scala)
at io.gatling.app.Gatling.main(Gatling.scala)
Caused by: java.lang.ClassNotFoundException: scala.Serializable
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 13 more
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':loadTest'.
> Process 'command '/Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 21s
5 actionable tasks: 5 executed
我没有Scala的经验,所以我很迷茫。有什么想法吗?谢谢。
1条答案
按热度按时间mbyulnm01#
Gatling不支持2.13.x版本的scala,把它改成2.12.10就修正了这个错误。
您的版本.gradle
implementation('org.scala-lang:scala-library:2.13.0')
我的工作版本
implementation('org.scala-lang:scala-library:2.12.10')
这是Gatling文档,其中版本依赖项被称为https://gatling.io/docs/current/installation/#scala-version