首页 > 解决方案 > 如何修复:java.lang.ClassNotFoundException:gradle gatlingRun 任务的 BasicSimulation?

问题描述

我正在尝试通过 gradle 运行一个加特林任务。我专门设置了我的 scala 源代码集,在运行 gatlingRun 之前运行 compileScala,但我不断收到错误消息: java.lang.ClassNotFoundException: BasicSimulation

如何正确设置任务?build.gradle: _

plugins {
    id "com.github.lkishalmi.gatling" version "3.0.2"
}
repositories {
    mavenCentral()
}
apply plugin: 'java'
apply plugin: 'scala'

sourceSets {
    main {
        scala {
            srcDirs = ['src/gatling/simulations/']
        }
    }
}



dependencies {
    compile "io.gatling:gatling-core:3.0.2"
    compile "io.gatling:gatling-http:3.0.2"
    compile 'io.gatling.highcharts:gatling-charts-highcharts:3.0.2'
    compile 'org.scala-lang:scala-library:2.11.8'
}

gatling {
    simulations = {
        include "*.scala"
    }
}


梯度语法: gradlew compileScala gatlingRun -Dorg.gradle.java.home=C:\Users\saber.alex\Documents\jre1.8.0_91

错误:


> Task :gatlingRun
16:22:52.131 [main] INFO io.gatling.core.config.GatlingConfiguration$ - Gatling will try to use 'gatling.conf' as custom config file.
16:22:52.910 [GatlingSystem-akka.actor.default-dispatcher-2] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started
16:22:54.045 [main] ERROR io.gatling.app.Gatling$ - Run crashed
java.lang.IllegalArgumentException: User defined Simulation class BasicSimulation could not be loaded
    at io.gatling.app.Selection$Selector.findUserDefinedSimulationInClassloader$1(Selection.scala:79)
    at io.gatling.app.Selection$Selector.$anonfun$singleSimulationFromConfig$4(Selection.scala:84)
    at scala.Option.orElse(Option.scala:289)
    at io.gatling.app.Selection$Selector.$anonfun$singleSimulationFromConfig$3(Selection.scala:84)
    at scala.Option.flatMap(Option.scala:171)
    at io.gatling.app.Selection$Selector.singleSimulationFromConfig(Selection.scala:82)
    at io.gatling.app.Selection$Selector.$anonfun$selection$1(Selection.scala:52)
    at scala.Option.getOrElse(Option.scala:121)
    at io.gatling.app.Selection$Selector.selection(Selection.scala:44)
    at io.gatling.app.Selection$.apply(Selection.scala:36)
    at io.gatling.app.Runner.run0(Runner.scala:74)
    at io.gatling.app.Runner.run(Runner.scala:61)
    at io.gatling.app.Gatling$.start(Gatling.scala:74)
    at io.gatling.app.Gatling$.fromArgs(Gatling.scala:47)
    at io.gatling.app.Gatling$.main(Gatling.scala:39)
    at io.gatling.app.Gatling.main(Gatling.scala)
Caused by: java.lang.ClassNotFoundException: BasicSimulation
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at io.gatling.app.Selection$Selector.$anonfun$singleSimulationFromConfig$2(Selection.scala:70)
    at scala.util.Try$.apply(Try.scala:209)
    at io.gatling.app.Selection$Selector.findUserDefinedSimulationInClassloader$1(Selection.scala:70)
    ... 15 common frames omitted

> Task :gatlingRun FAILED
3 actionable tasks: 3 executed

标签: javascalatestinggradlegatling

解决方案


一行回复You are missing the package here


推荐阅读