为什么“找不到隐含的” Scala + Intellij + ScalaTest + Scalactic中的错误,但不是来自sbt [英] Why "could not find implicit" error in Scala + Intellij + ScalaTest + Scalactic but not from sbt
问题描述
我的代码 100%来自sbt ,执行 sbt test
但在Intellij Idea中抛出编译错误。
I have this code that is working 100% from sbt , executing sbt test
but throw a compilation error in Intellij Idea.
import org.scalatest.{BeforeAndAfter, FunSuite, GivenWhenThen}
class SimpleTest extends FunSuite with GivenWhenThen with BeforeAndAfter {
test("Simple Test") {
Given("Why this error?")
assert("ok" === "ok")
}
}
错误是:
Error:(5, 10) could not find implicit value for parameter pos: org.scalactic.source.Position
Given("Why this error?")
Error:(5, 10) not enough arguments for method Given: (implicit pos: org.scalactic.source.Position)Unit.
Unspecified value parameter pos.
Given("Why this error?")
Error:(6, 11) could not find implicit value for parameter prettifier: org.scalactic.Prettifier
assert("ok" === "ok")
Error:(6, 11) macro applications do not support named and/or default arguments
assert("ok" === "ok")
Error:(6, 11) not enough arguments for macro method assert: (implicit prettifier: org.scalactic.Prettifier, implicit pos: org.scalactic.source.Position)org.scalatest.Assertion.
Unspecified value parameters prettifier, pos.
assert("ok" === "ok")
Error:(4, 23) could not find implicit value for parameter pos: org.scalactic.source.Position
test("Simple Test") {
按照建议刷新并重新加载:
After refresh and reload as suggested:
Error:(6, 11) exception during macro expansion:
java.lang.NoSuchMethodError: org.scalactic.BooleanMacro.genMacro(Lscala/reflect/api/Exprs$Expr;Ljava/lang/String;Lscala/reflect/api/Exprs$Expr;)Lscala/reflect/api/Exprs$Expr;
at org.scalatest.AssertionsMacro$.assert(AssertionsMacro.scala:34)
assert("ok" === "ok")
我正在使用:
IntelliJ IDEA 2016.3.2
Build #IU-163.10154.41, built on December 21, 2016
scalaVersion := "2.11.0",
"org.scalactic" %% "scalactic" % "3.0.1" % "test",
"org.scalatest" %% "scalatest" % "3.0.1" % "test"
注意:
- 使用文件 - >无效缓存/重新启动
无法解决问题
- 重现错误的示例: Github中的示例
推荐答案
响应底部的变通方法。 ;)
Workarounds at the bottom of the response. ;)
此问题与此BUG列表有关:
This problem is related with this list of BUGs:
- < a href =https://youtrack.jetbrains.com/issue/SCL-8167\"rel =nofollow noreferrer> SCL-8167
- SCL-11083
- SCL-8396
- SCL-10912
- SCL-8167
- SCL-11083
- SCL-8396
- SCL-10912
问题在那里是项目中的依赖项,使用测试范围,其他版本的scalatest和scalactic。
The problem is that there are dependencies in the project that are using, using test scope, other versions of scalatest and scalactic.
IntelliJ Idea混合编译范围和测试范围,但SBT正常工作。
IntelliJ Idea团队在BUG中表示他们正在开展这项工作。
IntelliJ Idea is mixing compile scope and test scope, but SBT is working correctly. IntelliJ Idea team said in the BUG that they are working in this.
我的解决方法目前已转移到相同的旧版本其他库正在用于测试。
My workaround, at the moment, has been move to the same older version that the other libraries are using for testing.
@ justin-kaeser已分配并正在努力解决此问题。 Thx!
@justin-kaeser is assigned and working to fix this. Thx!
在最新预览中与Scala插件有很多改进。
A lot of improvement related to the Scala plugin in that latest previews.
重现错误: https://github.com/angelcervera/idea-dependencies-bug
几个解决方法:
Few Workarounds:
- 删除有问题的依赖项来自项目结构 - >模块
- 排除sbt中的库。
- 使用相同的版本。
- 尝试使用最后一个EAP: https://www.jetbrains.com/idea/nextversion/
- Remove problematic dependencies from the Project structure -> Modules
- Exclude libraries in the sbt.
- Use the same version.
- Try with the last EAP: https://www.jetbrains.com/idea/nextversion/
这篇关于为什么“找不到隐含的” Scala + Intellij + ScalaTest + Scalactic中的错误,但不是来自sbt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!