Error "not found: value classOf" when building scala in IntelliJ IDEA, but building correctly in maven

I wrote a small part of the test code and compile it using IntelliJ IDEA 12 CE

import com.twitter.common.zookeeper.ZooKeeperClient import org.mockito.Mockito class MyResourceSpec { val zkClient = mock(classOf[ZooKeeperClient]) ... } 

I get the following error:

 not found: value classOf val zkClient = mock(classOf[ZooKeeperClient]) ^ 

However, I can successfully compile the project using mvn compilation. In addition, I have another test file in the same directory, "MyOtherResourceSpec.scala", which contains the exact lines of code.

Any thoughts on why this is not built correctly in IDEA?

Things I tried:

  • An employee suggested that IDEA might not recognize it as a scala file, and I tried clicking on a top-level project, and then clicking Maven> reimport.

  • Restarting IntelliJ

  • Copying all imports from "MyOtherResourceSpec.scala" in case something is missing

  • using Mockito.mock (classOf [ZooKeeperClient])

+4
source share
2 answers

Ok, I solved this by clicking File> Invalidate Caches and restarting IntelliJ. Then I did not need to import Predef.classOf.

I also had to remove the following import statement:

 import scala.Predef.String 
+10
source

Try importing Predef.classOf , which should help or just write Predef.classOf . IDEA uses its own external sbt-based compiler, there may be some problems.

-1
source

Source: https://habr.com/ru/post/1491011/


All Articles