You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

编写Gatling脚本时报Cannot resolve symbol core错误如何解决?

Gatling依赖导入失败修复方案

1. 修复项目坐标冲突

你当前pom.xml的项目自身坐标和官方gatling-core依赖重名,导致依赖加载冲突,替换pom头部的项目坐标为自定义标识即可:

<!-- 替换原有<groupId>、<artifactId>、<version>配置 -->
<groupId>自定义组织标识</groupId>
<artifactId>自定义项目名称</artifactId>
<version>1.0.0-SNAPSHOT</version>

2. 优化依赖配置

gatling-core是gatling-app的传递依赖,无需单独声明,同时统一使用已定义的版本变量,添加test作用域避免打包冲突:

<dependencies>
  <dependency>
    <groupId>io.gatling.highcharts</groupId>
    <artifactId>gatling-charts-highcharts</artifactId>
    <version>${gatling.version}</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>io.gatling</groupId>
    <artifactId>gatling-app</artifactId>
    <version>${gatling.version}</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>io.gatling</groupId>
    <artifactId>gatling-recorder</artifactId>
    <version>${gatling.version}</version>
    <scope>test</scope>
  </dependency>
  <!-- 可删除单独声明的gatling-core依赖 -->
</dependencies>

3. 补充Scala编译插件

Gatling脚本基于Scala开发,需要添加Scala编译插件才能正常识别依赖,在节点中添加如下配置:

<plugin>
  <groupId>net.alchim31.maven</groupId>
  <artifactId>scala-maven-plugin</artifactId>
  <version>4.5.4</version>
  <executions>
    <execution>
      <goals>
        <goal>compile</goal>
        <goal>testCompile</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <scalaVersion>2.12.12</scalaVersion>
  </configuration>
</plugin>

4. IDEA端生效操作

  • 右键pom.xml,选择Maven > Reload project刷新所有依赖
  • 右键src/test/scala目录,选择Mark Directory as > Test Sources Root标记为测试源码目录
  • 确认IDEA已安装Scala插件,项目JDK版本为1.8及以上

完成以上操作后,你需要的Scala导入语句即可正常识别。

内容的提问来源于stack exchange,提问作者Gökhan Uçar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.01 11:45:03