SBT + Idea 13 => Cannot resolve symbol - intellij-idea

I'm using SBT + Idea 13.1.1 and I have all my SBT file in red:
name := "Transformer"
version := "1.0"
libraryDependencies ++= Seq(
"com.github.scopt" %% "scopt" % "3.2.0",
"org.scalatest" % "scalatest_2.10" % "2.1.0" % "test"
)
It's saying
Cannot resolve symbol name/version
But Seq is ok. But it's all good to run the app from SBT cmd or even from Idea directly running the main or scalatests. I know it's not a lot information to troubleshoot but I don't know what to check else. Tell me if you have an idea I'll provide everything.
Cheers

To fix this, remove the folder .idea and reimport the project.
The root cause remains a mystery...

I had a similar problem when I updated to SBT 0.13.7. IntelliJ started marking operators such as := and ++ in red with message "Cannot resolve symbol"
My steps to fix this solution were as follows:
In IntelliJ under Files | Settings, I switched my SBT Runner to use a Custom Launcher (and gave my path to sbt-launch.jar which for me was /opt/sbt/bin/sbt-launch.jar).
After testing that I can still compile after #1 above, I then had to invalidate the cache and restart; under Files | Invalidate Caches / Restart...
That's it! :-)

In case none of the other solutions work and you are in the same boat as me, where you see a Cannot resolve symbol ... in the build.sbt and all files that have sbt dependencies, and where there are no sbt dependencies in External Libraries, running File | New | Module from Existing Sources... and selecting the build.sbt may fix it for you as it fixed it for me.

I had a similar problem on 14.1.2; in my case adding
libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.1" % "test"
and then trying to
import org.scalatest._
Would resulted in: cannot resolve symbol scalatest
Downgrading sbt (0.13.8 -> 0.13.7); in build.properties solved the problem.
here are more details.

Updating my build.properties from 0.13.8 to a newer version, like 0.13.15, solved it for me. Reference github issue.

Had the same problem in IDEA 14.0. Nothing above worked.
Upgrade to IDEA 14.1.1 did the trick.

Restarting IntelliJ fixed it for me.

It was about the .idea folder, if it is not included the codeStyles, Modules, libraries , it is giving that error. I fix it with import that folder from another project that has it.Then restart IntelliJ.

Related

Strange error when upgrading play-services-auth from 15.0.0 to 16.0.1

For my android project I upgraded play-services-auth library version from 15.0.0 to 16.0.1
Since then I see following error during the build and it also produces
ajcore files
I have removed my .gradle caches and done build and still see this error.
Anybody else seen this before, how do I fix it?
java.lang.IllegalStateException: Expecting .,<, or ;, but found authapi while unpacking Lcom/google/android/gms/common/api/internal/BaseImplementation$ApiMethodImpl;
at org.aspectj.util.GenericSignatureParser.parseClassTypeSignature(GenericSignatureParser.java:204)
at org.aspectj.util.GenericSignatureParser.parseFieldTypeSignature(GenericSignatureParser.java:155)
at org.aspectj.util.GenericSignatureParser.parseTypeArgument(GenericSignatureParser.java:267)
In my case, removing the Hugo logging plugin fixed the issue.
Check in your gradle file if you have it configured.
classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
It happens because some plugin (added by you) use libs:
org.aspectj:aspectjtools
or
org.aspectj:aspectjrt for codegeneration

Intelij IDEA scala test - compilation error, but ok in sbt

I'm getting following compilation error in Intelij Idea when running scalatests in my play framework application:
Error:(41, 54) Cannot find an instance of play.api.libs.json.JsObject
to WSBody. Define a BodyWritable[play.api.libs.json.JsObject] or
extend play.api.libs.ws.ahc.DefaultBodyWritables
val response = await(wsClient.url(testUrl).post(data))
Though when running sbt test it compiles and runs fine.
I've tried to clear Intelij cache and restart, didn't help.
What can be an issue?
I could resolve this issue by deleting .idea folder and re-importing the project.

IntelliJ Error:java: java.lang.ExceptionInInitializerError

Every time I encounter this exception in IntelliJ, I fix it trivially and forget the fix easily.
Code:
package whatever;
import org.junit.Test;
public class TestClass
{
#Test
void test() {}
}
Scenario:
Add new TestClass.
Right-click TestClass.
Select "Run 'TestClass'" to run test cases.
The "Messages Build" pane shows:
Information:javac 9-ea was used to compile java sources
Information:Module "dummy" was fully rebuilt due to project configuration/dependencies changes
Information:8/16/17 11:35 PM - Compilation completed with 1 error and 0 warnings in 1s 663ms
Error:java: java.lang.ExceptionInInitializerError
What can possibly go wrong?
What are the likely issues in this simple scenario?
IntelliJ: COMMUNITY 2017.1 (idea-IC-171.4424.56)
To fix the issue, I do:
File -> Project Structure... -> Project Settings / Project -> Project SDK.
Change from "9-ea" to "1.8".
DETAILS
Apparently, the issue is discrepancies in selected JDK-s to build (java 9) and run (java 8).
I'm not sure how "9-ea" gets re-selected there for the same project - neither IntelliJ itself runs in "9-ea" JRE (according to Help -> About) nor JAVA_HOME env var is set to it nor other possible settings (like Maven -> Runner) suggest any "9-ea".
I also didn't manage to run the test under the same JDK (java 9) which it gets compiled under. However, it's unclear what JDK tests are run under because IntelliJ reports only about JDK for compilation.
If you use Lombok: For me it was a solution to set the newest version for my maven lombok dependency in the pom.xml.
*<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
<version>1.18.8</version>
</dependency>*
I was facing same error when i tried to run my application in IntelliJ-2019.2 version. Below are the steps i followed to resolve this issue.
Versions:
IntelliJ : IDEA-IntelliJ-2019.2
Java : jdk1.8_221
Go to below path in IntelliJ
File -> Project Structure -> Project -> Project SDK -> (select java version which you want to use )
(In my case under 'project SDK' java-11 was selected, I changed it to 'java8')
Click on 'Apply' and then 'OK'.
I feel I ran into this issue because IntelliJ was trying to compile my java classes using in-built java-11 whereas my java classes are built on java-8. So when i explicitly configured java-8 in IntelliJ, It worked!! Hope this helps.
I started seeing this exception once I installed Java 11 in my machine. JAVA_HOME was by default pointing to Java 11 and my project was still in Java 8. Changing JAVA_HOME to Java 8 jdk fixed the issue for me.
If you have multiple projects each running on a different JDK, use this command to temporarily change the Java version per command.
JAVA_HOME=/path/to/JVM/jdk/Home mvn clean install
If you have recently updated your IDE then you can try these steps.
Delete .idea directory for the idea project/workspace
Then go to File -> Invalidate Caches / Restart...
Once Idea is restarted re-add/import your module(s)
I faced a similar issue with JARs and Jena (while run from IntelliJ it works).
I was using Apache Jena v4.0.0 in my project and have built a JAR (with a main class for the JAR to act as a console app).
The JAR builts successfully with IntelliJ but when run throws java.lang.ExceptionInInitializerError ... Caused by: java.lang.NullPointerException. NPE suggests that something was not initialized properly.
The jar built with previous version Jena 3.17.0 works perfectly.
What I did to fix it
I've opened both the JARs, compared their META-INF folders and encountered the difference in
my.jar\META-INF\services\org.apache.jena.sys.JenaSubsystemLifecycle
The new version (jena v4.0.0) contains only one line:
org.apache.jena.tdb.sys.InitTDB
The old version (jena v3.17.0) contains two different lines:
org.apache.jena.riot.system.InitRIOT
org.apache.jena.sparql.system.InitARQ
I've added the old two lines to the file and repacked new JAR with it:
org.apache.jena.tdb.sys.InitTDB
org.apache.jena.riot.system.InitRIOT
org.apache.jena.sparql.system.InitARQ
It resolved my issue.
Update: recent Jena v4.4.0 builts with the same "bug".
I'm not an expert and there is probably a better way than patching a JAR by hand.
But I still hope that this solution will help someone like me.

Kotlin - Error: Could not find or load main class _DefaultPackage

I followed the Kotlin tutorial for eclipse here : Getting Started With Eclipse Luna
However, I'm running into this error:
Error: Could not find or load main class _DefaultPackage
Anyone who knows to get around this?
This was a severe bug (KT-10221) in automatic generation of Launch Configuration in plugin version 0.4.0. It was fixed in 0.5.0 so the recommendend way to workaround is to update plugin.
The source of the problem was that the plugin used an old pattern for generating name of the class for main function that had been abandoned by Kotlin compiler.
It's possible to workaround it by editing launch configuration (Eclipse Menu -> Run -> Run Configurations...) by hand and changing Main class field in Java Application group. If the file is named hello.kt with no package directive, as it is described in tutorial, than corrected string should be HelloKt.
If file has name other.kt with package my.tutorial than the Main Class should contain my.tutorial.HelloKt. You can read more about it in the section Package-Level Functions of Calling Kotlin From Java page.
I have been getting the same issue. And after putting the right compiler output path, it got resolved.
Go to Project -> Project Compiler output :
In the text box, fill this:
[Absolute Path]/{Project Name}/out
In my case I was having this problem while trying to run the program using the Application Gradle plugin. The problem was in the mainClassName property using single quotes instead of double ones
This didn't work:
mainClassName = 'demo.HelloWorldKt'
With double quotes, it works:
mainClassName = "demo.HelloWorldKt"
For me it worked after I installed the correct JDK. I first had JDK 11 but the tutorial I did was with JDK 8 so after I installed this and set it in the "installed JREs" options it found the main class without having any "mainClassName" or any other option in the build.gradle file.
For me, it worked in a fresh eclipse workspace. Possibly, the Kotlin eclipse plugin is not playing well with other plugins (in my case, PyDev).
I'm creating a Kotlin Application with JavaFX and I had this issue until I went to:
Run > Run Configurations > Java Application > Common
I unticked "Allocate console" and it fixed the issue.

running sbt assembly in intellij

I'm new to scala and sbt and am having trouble running a project in intellij. This is the sample project I tried to import into intellij.
https://github.com/snowplow/spark-example-project
it works fine if I run the sbt assembly command from command line, but if I try to create an "application" run configuration in intellij I get an error in its dependencies: Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.util.Tool
How can I run and debug the sbt project in intellij?
Yes, it is a challenge to get spark to run in Intellij: and the "answers" on how to do so change based on the spark version and if you were running off of master or not.
The best bet is:
"Import project" and then navigate to the spark_home directory.
choose "sbt project" (or if you prefer "maven project")
rest of options you should be able to use the defaults.
Caveat: this process is working in master from around the beginning of 2015 - and in the released 1.3.0 branch as of the middle of march 2015.
Previously there would be some involved surgery required to the Intellij project/modules after the import were completed.
The important part is getting your dependencies correct.
I like to create a lib folder and place my spark files there, e.g.
within lib:
spark-streaming_2.10-2.1.0.jar
spark-sql_2.10-2.1.0.jar
spark-core_2.10-2.1.0.jar
Then my sbt file:
name := "Project_Name"
version := "1.0"
scalaVersion := "2.10.6"
retrieveManaged := true
// https://mvnrepository.com/artifact/org.apache.spark/spark-core_2.10
libraryDependencies += "org.apache.spark" % "spark-core_2.10" % "2.1.0"
// https://mvnrepository.com/artifact/org.apache.spark/spark-sql_2.10
libraryDependencies += "org.apache.spark" % "spark-sql_2.10" % "2.1.0"
// https://mvnrepository.com/artifact/org.apache.spark/spark-streaming_2.10
libraryDependencies += "org.apache.spark" % "spark-streaming_2.10" % "2.1.0" % "provided"
As you can see, I strongly encourage you to get both the .jar and the string you stick in your sbt file from https://mvnrepository.com
Also, check out the jar file versions. They should be the same (2.10-2.1.0 in my case)