I have an issue when trying to import in scala. The object Database
exists under com.me.project.database
but when I try to import it:
In my case I also needed to check that object which is not found as a member of package is compiled successfully.
I had faced similar issue where IntelliJ showed error on importing one file from the same project.
What did not resolve the issue in my case:
_root_
in import statementWhat actually resolved the issue:
I was using IDEA (2019.2.2 Ultimate Edition) on macOs mojave 10.14.6
I had a similar situation, which was failing in both IntelliJ and maven on the command line. I went to apply the suggested temp fix (adding _root_
) but intellij was glitching so bad that wasn't even possible.
Eventually I noticed that I had mis-created a package so that it repeated the whole path of the package. That meant that the directory my class was in had a subfolder called "com", and the start of my file looked like:
package com.mycompany.mydept.myproject.myfunctionality.sub1
import com.holdenkarau.spark.testing.DataFrameSuiteBase
where I had another package called com.mycompany.mydept.myproject.myfunctionality.sub1.com.mycompany.mydept.myproject.myfunctionality.sub2
And the compiler was looking for "holdenkarau" under com.mycompany.mydept.myproject.myfunctionality.com and failing.
In my case, In Intellij, Just renaming the package file to something else >> see if it updates the import statements >> run the code >> then renaming back to the original name worked.
imports can be relative. Is that the only import you have? be careful with other imports like
import com.me
ultimately, this should fix it, then you can try to find more about it:
import _root_.com.me.project.database.Database
If you are using gradle
as your build tool, then ensure that jar
task is not disabled.
I had multiple modules in my project, where one module was dependent on a few other modules. However, I had disabled jar
task in build.gradle
:
jar {
enabled = false
}
That caused it to fail to resolve classes in the dependent modules and fail with the above error.