Gatling+Grpc测试报错:FindCheckBuilder缺失的解决与根因分析
问题:Gatling与gRPC集成测试编译报错
测试脚本
package load import com.github.phisgr.gatling.grpc.Predef._ import example.myapp.helloworld.grpc.hello_world.{GreeterServiceGrpc, HelloRequest} import io.gatling.core.Predef.{stringToExpression => _, _} import io.grpc.Status import load.Constants.grpcPsgConf import io.gatling.core.Predef._ import io.gatling.http.Predef._ import io.gatling.jdbc.Predef._ import scala.concurrent.duration.DurationInt import scala.language.postfixOps class GrpcSimulation extends Simulation { val scn = scenario("Make Hello Request and Get Response") .exec(grpc("Hello Request") .rpc(GreeterServiceGrpc.METHOD_SAY_HELLO) .payload(HelloRequest("Gatling Load Test")) .extract(_.message.some)(_ saveAs "message") .check(statusCode is Status.Code.OK) ) .exec(grpc("Hello Request with parameter from session") .rpc(GreeterServiceGrpc.METHOD_SAY_HELLO) .payload(session => HelloRequest(session.attributes("message").asInstanceOf[String])) .check(statusCode is Status.Code.OK) ) setUp(scn.inject(rampUsersPerSec(1) to (2) during (20 seconds)).protocols(grpcPsgConf.shareChannel)) }
报错信息
执行sbt "Gatling / testOnly *.GrpcSimulation"时出现以下错误:
[error] C:\Users\TriNP\Desktop\gatlingGrpc\gatling-grpc-tests-sample\src\test\scala\load\BiDiStreamingSimulation.scala:16:23: Symbol 'type io.gatling.core.check.FindCheckBuilder' is missing from the classpath. [error] This symbol is required by 'value com.github.phisgr.gatling.grpc.check.GrpcCheckSupport.findCheckBuilder'. [error] Make sure that type FindCheckBuilder is in your classpath and check for conflicting dependencies with `-Ylog-classpath`. [error] A full rebuild may help if 'GrpcCheckSupport.class' was compiled against an incompatible version of io.gatling.core.check. [error] val bidiCall = grpc("BiDi call").bidiStream("bidi") [error] ^ [error] C:\Users\TriNP\Desktop\gatlingGrpc\gatling-grpc-tests-sample\src\test\scala\load\GrpcSimulation.scala:20:28: Symbol 'type io.gatling.core.check.FindCheckBuilder' is missing from the classpath. [error] This symbol is required by 'value com.github.phisgr.gatling.grpc.request.CallDefinition.ts'. [error] Make sure that type FindCheckBuilder is in your classpath and check for conflicting dependencies with `-Ylog-classpath`. [error] A full rebuild may help if 'CallDefinition.class' was compiled against an incompatible version of io.gatling.core.check. [error] .payload(HelloRequest("Gatling Load Test")) [error] ^ [error] two errors found [error] (Test / compileIncremental) Compilation failed [error] Total time: 1 s, completed 09:20:29, 25 thg 9, 2023 sbt:gatling-grpc-tests-sample> reload [info] welcome to sbt 1.9.6 (Oracle Corporation Java 17.0.8) [info] loading settings for project gatling-grpc-tests-sample-build from assembly.sbt,gatling.sbt,plugins.sbt,scalapb.sbt ... [info] loading project definition from C:\Users\TriNP\Desktop\gatlingGrpc\gatling-grpc-tests-sample\project [info] compiling 1 Scala source to C:\Users\TriNP\Desktop\gatlingGrpc\gatling-grpc-tests-sample\project\target\scala-2.12\sbt-1.0\classes ... [error] C:\Users\TriNP\Desktop\gatlingGrpc\gatling-grpc-tests-sample\project\Dependencies.scala:2:11: object gatling is not a member of package sbt.io [error] import io.gatling.core.Predef._ [error] ^ [error] one error found [error] (Compile / compileIncremental) Compilation failed
当前配置文件
build.sbt
import Dependencies._ name := "gatling-grpc-tests-sample" version := "0.1" scalaVersion := "2.13.12" libraryDependencies ++= gatlingDependencies ++ loggingDependencies ++ grpcDependencies ++ Seq( "com.github.daddykotex" %% "courier" % "3.0.0-M2a", "com.typesafe" % "config" % "1.4.1", "com.google.guava" % "guava" % "30.1.1-jre", "com.typesafe.akka" %% "akka-actor-typed" % "2.6.10", "com.typesafe.akka" %% "akka-protobuf-v3" % "2.6.10", "com.typesafe.akka" %% "akka-stream" % "2.6.10" ) enablePlugins(GatlingPlugin) PB.targets in Compile := Seq( scalapb.gen() -> (Compile / sourceManaged).value / "scalapb" )
gatling.sbt
addSbtPlugin("io.gatling" % "gatling-sbt" % "4.5.0")
plugins.sbt
addSbtPlugin("com.lightbend.akka.grpc" % "sbt-akka-grpc" % "1.1.1")
scalapb.sbt
addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.0") libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.10.10"
根本原因
- 依赖版本不兼容:
com.github.phisgr/gatling-grpc插件版本与当前使用的Gatling 4.5.0不匹配。Gatling 4.x对核心检查模块(io.gatling.core.check)进行了API调整,而旧版本的gatling-grpc插件编译依赖的是Gatling 3.x的API,导致找不到FindCheckBuilder类。 - sbt项目定义错误:
project/Dependencies.scala中错误导入了io.gatling.core.Predef._,该文件属于sbt的构建定义代码(运行在sbt类加载器下),而Gatling核心依赖仅在测试代码类路径中,因此sbt无法找到该包。
修复步骤
1. 修正Dependencies.scala的错误
修改project/Dependencies.scala,移除错误的Gatling导入,改为直接声明依赖版本:
object Dependencies { val gatlingVersion = "4.5.0" val scalapbVersion = "0.11.14" val akkaGrpcVersion = "2.3.1" val gatlingDependencies = Seq( "io.gatling.highcharts" % "gatling-charts-highcharts" % gatlingVersion % Test, "io.gatling" % "gatling-test-framework" % gatlingVersion % Test, "com.github.phisgr" %% "gatling-grpc" % "0.19.0" % Test // 新增兼容Gatling 4.x的版本 ) val loggingDependencies = Seq( // 补充你的日志依赖,比如ch.qos.logback:logback-classic:1.4.8 ) val grpcDependencies = Seq( "io.grpc" % "grpc-netty-shaded" % "1.59.0", "com.thesamet.scalapb" %% "scalapb-runtime-grpc" % scalapbVersion % Compile ) }
2. 更新scalapb相关插件版本
修改scalapb.sbt,使用与Scala 2.13兼容的新版本:
addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.6") libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.11.14"
3. 更新akka-grpc插件版本
修改plugins.sbt,使用兼容当前Akka版本的插件:
addSbtPlugin("com.lightbend.akka.grpc" % "sbt-akka-grpc" % "2.3.1")
4. 清理并重新编译
执行以下命令彻底清理旧编译产物并重新构建:
sbt clean sbt compile sbt "Gatling / testOnly *.GrpcSimulation"
版本匹配建议
确保所有核心组件版本相互兼容:
- sbt:1.9.6(兼容Scala 2.13.x,无需调整)
- Scala:2.13.12(与Gatling 4.x、scalapb 0.11.x兼容)
- Gatling:4.5.0(对应gatling-grpc版本0.19.0)
- scalapb:0.11.14(兼容Scala 2.13,支持最新gRPC版本)
- akka-grpc:2.3.1(兼容Akka 2.6.x,与当前Akka版本匹配)
内容的提问来源于stack exchange,提问作者TriNguyen
相关产品推荐
相关产品推荐

