[英]IntelliJ IDEA Scala inspection : import play.api.xxx conflict with com.company.play package
I want to make a helper class at the root of my core
project using play-json from typesafe, something like 我想使用来自typesafe的play-json在core
项目的根目录创建一个帮助器类,例如
package com.company
import play.api.libs.json.JsValue
object Helper {
implicit class RichJson(json: JsValue) {
def doStuff() //...
}
}
The problem is that I have somewhere else in the project a package com.company.play 问题是我在项目的其他地方有一个包com.company.play
package com.company.play
class Foo() { //...
}
In IntelliJ IDEA 2018.2.4 CE, the line import play.api.libs.json.JsValue
is in error with telling me "cannot resolve symbol api" and when Ctrl+Click on the play
it goes to the folder containing my Foo.scala file 在IntelliJ IDEA 2018.2.4 CE中, import play.api.libs.json.JsValue
行import play.api.libs.json.JsValue
是错误的,告诉我“无法解析符号api”,当按Ctrl +单击play
它将转到包含我的Foo.scala的文件夹文件
If I compile the solution with sbt outside of IDEA, there is no problem. 如果我在IDEA之外使用sbt编译解决方案,则没有问题。
If I put the Helper
object in a subpackage (eg com.company.common
) there is no error (which also means the dependency is correct in my build.sbt) 如果我将Helper
对象放在子包中(例如com.company.common
),则不会出现错误(这也意味着在build.sbt中,依赖关系是正确的)
I don't understand why IDEA miss this, com.company.play
isn't even in the dependencies of the core
project. 我不明白为什么IDEA会错过这一点, com.company.play
甚至不在core
项目的依赖项中。 I already tried to invalidate cache, and it doesn't help. 我已经尝试使缓存无效,这没有帮助。
The problem is that Intellij gives precedence to the package play
into your project, instead of the package coming from the framework, when resolving the import of JsValue
inside com.company
scope. 问题是,在解决com.company
范围内的JsValue
的导入时,Intellij优先考虑将包play
到项目中,而不是来自框架的包。
If you really want to keep that name for com.company.play
, there is a simple workaround using a fully-qualified import, just prefix like this: 如果您确实想为com.company.play
保留该名称,则有一个使用完全限定的导入的简单解决方法,只是这样的前缀:
import _root_.play.api.libs.json.JsValue
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.