scalac: missing or invalid dependency detected while loading class file 'CassandraSession.class' - scala

I've been developing in Javadsl with Maven, but I haven't been able to compile the project in my intellij 2016 since I added Scaladsl libraries.
This is the error I am getting:
Error:scalac: missing or invalid dependency detected while loading
class file 'CassandraSession.class'. Could not access term session in
package akka.persistence.cassandra, because it (or its dependencies)
are missing. Check your build definition for missing or conflicting
dependencies. (Re-run with -Ylog-classpath to see the problematic
classpath.) A full rebuild may help if 'CassandraSession.class' was
compiled against an incompatible version of
akka.persistence.cassandra.
I tried the followings:
Invalidate Cache and Restart the Intellij
Maven Clean Install (failed)
Restart the PC
None of them worked.
Does anyone know how to fix this problem?
This is my POM.xml for the module which I am using both Scaladsl and Javadsl.
Thanks!

Related

Why does Eclipse turn a maven runtime dependency into a compile dependency?

I have a maven project imported into Eclipse Oxygen. Eclipse reports no compile issues (Alt + F5). When I run maven from the command line I get
[ERROR] /home/dean/src/TAP3UIs/TAP3Desktop/src/main/java/com/ms/tap3/controller/RequestAccessController.java:[8,30] package com.google.common.base does not exist
That package does exist in my .m2/repository in guava-15.0.jar. I can also see it in Eclipse mvn dependencies. When I check the mvn dependency:tree for the project I see
[INFO] | | | +- com.google.guava:guava:jar:15.0:runtime
It is a runtime transitive dependency on the command line, which explains why it doesn't compile on the command line. Somehow Eclipse has turned a transitive dependency from runtime to compile.
Does anyone know why this happens and how I make Eclispe m2e respect the scope of the transitive dependencies?
Currently, neither JDT nor m2e support multiple classpaths per project which is required to support different scopes.
See: Eclipse bug 486035 - Different classpath containers for different scopes
Update:
Since Eclipse Photon (4.8) which was released in June 2018 this is now supported. See Eclipse bug 526858 and my video showing this in action.
The main point is this: If you import external classes in your source code, you must set them as compile dependencies, and never trust the fact that they might already be transitive dependencies (because, since they are transitive, you have not direct control over them, so in a future version they might diseappear as well).
What is happening is this:
You need some classes from com.google.common.base package, so you need to set com.google.guava:guava:jar:15.0 as a dependency.
Instead, you didn't because you realised it was already a transitive dependency, but you missed the fact that is a runtime dependency.
Eclipse M2 does not distinguish the different Maven's standard classpaths, so it treats all dependencies as if they were of "compile" scope. So Eclipse includes guava-15.0.jar in the compilation and the project is compiled OK.
Maven, instead, won't include a runtime dependency in the compilation phase, so a compile error is raised.
In brief: You should include guava-15.0 (as well as any other artifact your code needs) as a direct dependency (with compile scope) in your pom file.

Spark-Scala Invalid dependency while loading class file

Type missing or invalid dependency detected while loading class file 'SQLImplicits.class'. Could not access type Encoder in package org.apache.spark.sql, because it (or its dependencies) are missing. Check your build definition for missing or conflicting dependencies. (Re-run with -Ylog-classpath to see the problematic classpath.) A full rebuild may help if 'SQLImplicits.class' was compiled against an incompatible version of org.apache.spark.sql. SparkScala Unknown Scala Problem.
Description Resource Path Location Type
missing or invalid dependency detected while loading class file 'package.class'. Could not access type Row in package org.apache.spark.sql, because it (or its dependencies) are missing. Check your build definition for missing or conflicting dependencies. (Re-run with -Ylog-classpath to see the problematic classpath.) A full rebuild may help if 'package.class' was compiled against an incompatible version of org.apache.spark.sql. SparkScala Unknown Scala Problem
I'm new to this world. Any help would be highly appreciated!!
I have installed both 2.11 versions of spark and scala.
This was caused due to d not matching the org.apache.spark.sql version with org.apache.spark core. make sure both have same version.
I hope this will solve the issue.

Intellij sbt won't resolve dependencies' dependencies

I have a Intellij Scala project, that depends on another lib, which in turn depends on some other libs (gson, log4j...), but somehow Intellij won't add those transitive dependencies to my project, so when I run my main method, jvm always complains no class found. I also tried sbt update and sbt update-classifier, they won't resolve down the dependency path as well. How can I have sbt resolve all levels of dependencies?
If all works in SBT command lines but not in Idea then remove the .idea folder and reload the SBT project in Idea.
I should warn that you will loose the project configs (such as run configs) by doing that.
I finally figure out what was wrong, it was the sbt-s3-resolver plugin I was using couldn't resolve maven style dependencies, I used an another plugin which supports maven libs and it worked. But I still couldn't figure out why it worked before.

How to resolve this exception

This Exception invoked and not able to resolved it ...
Error:scalac: missing or invalid dependency detected while loading class file 'GenericCollection.class'.
Could not access term play in package <root>,
because it (or its dependencies) are missing. Check your build definition for
missing or conflicting dependencies. (Re-run with `-Ylog-classpath` to see the problematic classpath.)
A full rebuild may help if 'GenericCollection.class' was compiled against an incompatible version of <root>.
The error message is basically saying that GenericCollection.class has a reference to the _root_.play package, but the play package can't be found.
You have to add a dependency to the library that provides the play package, which is very likely part of the play framework.

How to resolve reference to twirl generated template class in Scala-IDE?

Using twirl for generating template class. Everything is working fine with sbt and the webpages are rendering.
I am using Scala-IDE for development. And in the Scala-IDE the reference to the template class i.e. "html.test()", test is the template name, is showing as an error.
This is the error:
Description Resource Path Location Type
missing or invalid dependency detected while loading class file 'test.class'.
Could not access term api in value .twirl, because it (or its dependencies) are missing.
Check your build definition for missing or conflicting dependencies. (Re-run with -Ylog-classpath to see the problematic classpath.) A full rebuild may help if 'test.class' was compiled against an incompatible version of .twirl. ApiService.scala /api/src/main/scala/com/komma/api/rest line 97 Scala Problem.
I did a clean and it is giving "not found: value html" error now.
Is there any way to resolve this error in the scala IDE ?
Thanks.
Re-running sbt eclipse added target/scala-2.11/twirl/main as a source folder which resolved the compilation errors for me.
For my twirl configuration, sbt eclipse did not add the twirl output directory as a source folder. Adding
target/scala-2.11/twirl/main to the eclipse project build path through the Add Folder button, under Java Build Path, by hand, was my solution.