问题
我正在扩展现有的性能测试项目,这是一个使用 Gatling 进行模拟并使用 Maven 作为构建工具的 Scala 项目。我需要 Scalaj 作为新的依赖项。我从 2.12.8
更改了 Scala 版本至 2.13.0
这样我就可以使用最新版本的 Scalaj ( 2.4.2
),这导致使用 /
的类出现编译错误来自 io.gatling.commons.util.PathHelper
的运算符(operator).
我尝试过的一些东西
只有在使用 IntelliJ 配置运行项目时才会出现此错误,但在运行 mvn package
时不会出现此错误和 mvn gatling:test
.如果我使用 IntelliJ 配置和 Scala 2.12.8
,我也不会收到错误消息.
我认为这可能是兼容性问题并检查了 Gatling 文档 & release notes但他们最后一件事mentioned关于 Scala 兼容性来自 2.3
在 Gatling 上需要 Scala 2.12
.我想这意味着 2.12
或更高。我现在错了吗?
我还检查了 IntelliJ Scala 插件是否有更新,但一无所获。
重现问题的代码
这是我的 pom.xml
的相关部分文件:
<dependencies>
<dependency>
<groupId>io.gatling.highcharts</groupId>
<artifactId>gatling-charts-highcharts</artifactId>
<version>3.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.13.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.scalaj/scalaj-http -->
<dependency>
<groupId>org.scalaj</groupId>
<artifactId>scalaj-http_2.13</artifactId>
<version>2.4.2</version>
</dependency>
</dependencies>
未编译的类(其中 /
是导入类的函数):
package com.example.mypackage
import io.gatling.commons.util.PathHelper._
object PathHelper {
val projectRootDir: Path = "root_directory"
val mavenSourcesDirectory: Path = projectRootDir / "src"
}
入口点示例:
package com.example.mypackage
object ApplicationRunner {
def main(args: Array[String]): Unit = {
println(mavenSourcesDirectory.toString)
}
}
我的结果
我在点击 IntelliJ 的“运行”按钮后收到的错误消息(我将一些不相关的项目特定信息更改为 <>
之间的注释):
Error:scalac: Error: assertion failed:
no extension method found for:
method /:(pathString: String)java.nio.file.Path
Candidates:
Candidates (signatures normalized):
"
while compiling: /home/me/example-repo/src/test/scala/com/example/mypackage/PathHelper.scala
during phase: globalPhase=erasure, enteringPhase=refchecks
library version: version 2.13.0
compiler version: version 2.13.0
reconstructed args: -classpath <.jar path for every dependency I use>
last tree to typer: Select(Apply(method to), foreach$mVc$sp)
tree position: <some line in an entirely different class where I don't use PathHelper>
tree tpe: (f: Int => Unit)Unit
symbol: (final override) method foreach$mVc$sp in class Range
symbol definition: final override def foreach$mVc$sp(f: Int => Unit): Unit (a MethodSymbol)
symbol package: scala.collection.immutable
symbol owners: method foreach$mVc$sp -> class Range
call site: object PathHelper in package mypackage in package mypackage
== Source file context for tree position ==
12 <line from file>
13 <line from file>
14 <tree position>
15 <line from file>
at scala.reflect.internal.SymbolTable.throwAssertionError(SymbolTable.scala:170)
at scala.tools.nsc.transform.ExtensionMethods.$anonfun$extensionMethod$1(ExtensionMethods.scala:54)
at scala.tools.nsc.transform.ExtensionMethods.extensionMethod(ExtensionMethods.scala:49)
at scala.tools.nsc.transform.Erasure$ErasureTransformer$$anon$4.preEraseNormalApply(Erasure.scala:1102)
at scala.tools.nsc.transform.Erasure$ErasureTransformer$$anon$4.preEraseApply(Erasure.scala:1204)
at scala.tools.nsc.transform.Erasure$ErasureTransformer$$anon$4.preErase(Erasure.scala:1214)
at scala.tools.nsc.transform.Erasure$ErasureTransformer$$anon$4.transform(Erasure.scala:1333)
at scala.tools.nsc.transform.Erasure$ErasureTransformer$$anon$4.transform(Erasure.scala:993)
at scala.reflect.internal.Trees$ValDef.$anonfun$transform$4(Trees.scala:405)
at scala.reflect.api.Trees$Transformer.atOwner(Trees.scala:2625)
<and so on for 78 more lines of stack trace>
注意事项
毕竟,对我来说它看起来像是一个 IntelliJ 依赖项处理问题。 我已经找到了两个解决方法,所以这个问题并没有让我崩溃,但它很不方便,我有兴趣了解如何修复它。另外,我对 Scala 还很陌生,所以我很有可能遗漏了一些东西。
如有任何见解,我们将不胜感激。
最佳答案
我自己还没有尝试过,但是 Gatling 似乎还不兼容 Scala 2.13:
https://github.com/gatling/gatling/issues/3566
回到 2.12 可能是最简单的。
关于scala - IntelliJ 中 Scala 2.13.0 的 Gatling 兼容性问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56705406/