Error importing SBT project in IntelliJ / no src folder appears - scala

I'm new to working with both IntelliJ and Scala, so I've been trying to set up a basic HelloWorld project using it. However once I try to load the project I'm met with two problems
I get an error saying there was an "Error while importing SBT project"
No 'src' folder appears on the project tree
I've seen similar problems here and here, but I still can't get the project to load properly.
For some reason this site doesn't let you post an image until you have 10 reputation, so here is a link to the error message I'm receiving http://i.imgur.com/vDZB6SA.png.
From the looks of it, it seems like it's unable to download the necessary dependencies, however I was able to download the scala plugin earlier, so I can't see why there would be a problem now.
I tried following the advice here on updating the proxy settings, but that doesn't work either.
Has anyone encountered a similar problem? I'm really stuck here on how to proceed.
EDIT 1:
Details on IntelliJ
IntelliJ IDEA 2016.2.3
Build #IC-162.1812.17, built on August 30, 2016
JRE: 1.8.0_65-b17 amd64
JVM: Java HotSpot(TM) 64-Bit Server VM by Oracle Corporation
Setting up the proejct:
I just followed an example and went to New Project > Scala > SBT > name project and finish. Then once it loads I get the error displayed in the picture above. The SBT version is 0.13.8 and the Scala version is 2.11.8

Related

intelliJ multiple scala-library*.jar file

I tried to run scala app in IJ community version 2018.3.6, and ran into this error:
Error:scalac: Multiple 'scala-library*.jar' files (scala-library-2.12.8.jar, scala-library-2.12.8.jar) in Scala compiler classpath in Scala SDK sbt: org.scala-lang:scala-library:2.12.8:jar
and I checked hte .idea/libraries folder saw:
sbt__org_scala_lang_scala_library_2_11_8.jar.xml
sbt__org_scala_lang_scala_library_2_12_8.jar.xml
after I delete sbt__org_scala_lang_scala_library_2_11_8.jar.xml still got the same error, then i deleted all 2.11.8 scala*.files still got hte same error
I also tried to open the same project in IJ community version 2019.2.4, it complained:
Cannot determine module type ("SBT_MODULE") for the following module:
there is no 'sbt' tool listed in Preference -> Build, Execution, Deployment -> Build Tools
anyone know how to get it work?
## FIX
i ended up to uninstall and reinstall Scala plugin in IJ 2019.2.4 to get it working again.

Cannot sync scala project in IntelliJ IDEA Community 2019.2.4

Scala newbie here: I am attempting to get started with Scala using Windows 10 (Pro 10.0.18362 Build 18362) Hyper-v Quick Create of Ubuntu (18.04.3 LTS). I installed the JRE and JDK (11.0.4). I installed IntelliJ IDEA 2019.2.4. I added the Plugin for Scala (plugin 2019.2.37). I have left the SBT Executor 1.2.1 disabled for now: it was enabled earlier but it does not seem to affect the results. I tried to create the HelloWorld application (see below). I added the Scala Framework to the Project and, after encountering the error below, the Mavin framework (adding Mavin did not help.) After correcting the error in bulid.sbt it looks like this:
import com.sun.tools.javac.resources.version
name := "HelloWorld"
version := "0.1"
scalaVersion := "2.13.1"
I create a Scala worksheet by right-click on scala folder and selecting Scala Worksheet:
object Hello extends App {
println("Hello, World!")
}
I get a pop-up saying Maven project needs to be imported. This succeeds quickly. I get a second one saying sbt project needs to be imported. This fails:
sbt.librarymanagement.ResolveException: Error downloading org.scala-sbt:zinc-compile-core_2.12:1.3.1
and this error accompanies it:
not found: https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/org.scala-sbt/util-position_2.12/1.3.2/ivys/ivy.xml
The first ResolveException appears to be about a part of Mavin, but that should be present. This error message is followed by many other "not found" errors, but I assume they all stem from the above errors or are related. I cannot seem to find a solution: most of the information and examples on IntelliJ IDEA Scala on the web are several years (editions) out of date.
It appears Maven apps are to be deployed to Apache Spark. Not my intention, but in the Mavin panel I can successfully clean, validate and compile.
When I Run the Hello.sc app, I get this:
/snap/intellij-idea-community/185/jbr/bin/java -javaagent:/snap/intellij-idea-community/185/lib/idea_rt.jar=37033:/snap/intellij-idea-community/185/bin -Dfile.encoding=UTF-8 -classpath /home/perfwise/ideaProjects/HelloWorld/target/classes:/home/perfwise/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.13.1.jar:/home/perfwise/.ivy2/cache/org.scala-lang/scala-reflect/jars/scala-reflect-2.13.1.jar:/home/perfwise/.ivy2/cache/org.scala-lang/scala-library/srcs/scala-library-2.13.1-sources.jar:/home/perfwise/.ivy2/cache/org.scala-lang/scala-reflect/srcs/scala-reflect-2.13.1-sources.jar Hello
Error: Could not find or load main class Hello
Caused by: java.lang.ClassNotFoundException: Hello
Process finished with exit code 1
I would have expected this to work. Any pointers will be much appreciated.

Intellij IDEA: Scala Worksheet misbehaving

I'd like to test the Scala code that I've just written by running small fragments of it separately in a Scala Worksheet. What sounds like a trivial affair isn't working because:
After updating the code, the Scala Worksheet keeps running the obsolete code. I've already ticked the Make Project checkbox and have even tried the enabling Use REPL Mode without luck. When even a complete cycle of sbt reload > sbt update > sbt clean > sbt compile doesn't fix the issue, I wonder what will.
Even if I manage to fix the above issue, next thing is that I'm unaware of any possible way to view the log messages generated by typesafe Logger within IntelliJ IDEA. There might be some file where these logs are being dumped but leaving the IDE to view log file sounds less-than-ideal in 2018. The only other alternative would be to manually replace (or augment) each log line throughout my project with println. Something makes me think that there's got to be a better way. The IntelliJ docs page for Setting Log Options isn't very helpful as it is outdated and I cannot find the same UI as shown in the screenshots over there
Assuming above two problems are sorted, there's yet another hurdle: the infamous Internal Error: null problem when trying to run the worksheet. And from what I've observed, once I hit this error, only restarting IntelliJ overcomes it.
Here are my configurations
IDE
- IntelliJ IDEA 2017.3.4 (Community Edition)
- Build #IC-173.4548.28, built on January 30, 2018
- JRE: 1.8.0_152-release-1024-b11 x86_64
- JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
- Mac OS X 10.13.3
- Scala Plugin Version: 2017.3.11.1
Project
- Scala 2.11.11
- SBT 1.0.3
- Typesafe Scala Logging "com.typesafe.scala-logging" %% "scala-logging" % "3.7.2"

Scala: IntelliJ highlights correct code in red

One fine day IntelliJ started highlighting my working Scala code in red. While following commands run without a hitch, IntelliJ thinks that code is full of errors an missing a lot of dependencies.
sbt clean
sbt reload
sbt update
sbt compile
sbt assembly
It reports a lot of Cannot resolve symbols in imports, classes and method-calls on objects like the following. Moreover, it thinks a lot of imports are unused (for the symbols that it can't find)
Interestingly, all this is happening in only one of my projects (that contains two submodules inside parent module), while other Scala projects (including those containing submodules) are working fine.
Things that I've tried without luck:
Delete (rm -rf) build-related directories like .idea, target, ~/.ivy2/caches
Invalidate Caches / Restart...
Update IntelliJ IDEA and Scala plugin to latest versions
Close and re-import the project, quit IntelliJ, reboot the PC (!)
I'm using:
IntelliJ IDEA 2017.3.2 (Community Edition)
Build #IC-173.4127.27, built on December 25, 2017
JRE: 1.8.0_152-release-1024-b8 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.13.2
My project configurations are:
Scala v2.11.11
SBT v1.0.3
Once again, I'd like to remind that my Scala code is completely functional and that I'm able to run the JAR generated by sbt assembly elsewhere without an issue.
This solution worked for me: Why does intellij IDEA highlight build.sbt?
Go to the menu: File > Invalidate Caches/Restart
Such things happen when project SDK is not set. Also make sure that you have Add Framework Support -> Scala enabled.

play -help gives Error: Could not retrieve sbt 0.13.0: missing sbt.xMain

I created a new app using command play new hello and cd'ed into the directory. When I type play in the directory, I receive the following error:
akshay#Akshay:~/play/testn$ play -help
Java HotSpot(TM) Server VM warning: ignoring option MaxPermSize=512M; support was removed in 8.0
Getting org.scala-sbt sbt 0.13.0 ...
:: retrieving :: org.scala-sbt#boot-app
confs: [default]
0 artifacts copied, 43 already retrieved (0kB/45ms)
Error: Could not retrieve sbt 0.13.0: missing sbt.xMain
Play was working fine in my old Ubuntu box. Today only I got a fresh copy of Ubuntu 12.04 32 bit. I know it is error due to change in version, but certainly, I am not able to solve this. Please help me on this.
In checked .sbt/boot/update.log and I can see this :
trying http://repo.typesafe.com/typesafe/ivy-releases/org.sonatype.oss/oss-parent/7/jars/oss-parent.jar
tried http://repo.typesafe.com/typesafe/ivy-releases/org.sonatype.oss/oss-parent/7/jars/oss-parent.jar
HTTP response status: 404 url=http://repo.typesafe.com/typesafe/ivy-releases/org.sonatype.oss/oss-parent/7/jars/oss-parent.jar
CLIENT ERROR: Not Found url=http://repo.typesafe.com/typesafe/ivy-releases/org.sonatype.oss/oss-parent/7/jars/oss-parent.jar
typesafe-ivy-releases: resource not reachable for org.sonatype.oss#oss-parent;7: res=http://repo.typesafe.com/typesafe/ivy-releases/org.$
trying http://repo1.maven.org/maven2/org/sonatype/oss/oss-parent/
Though error was coming from a fresh ubuntu installation with oracle jdk 8, I tried completely removing jdk and then installing jdk 7, but still no solution. Since it was a fresh installation, I reinstalled ubuntu and installed jdk 7 and problem is solved. Not sure why is it contradictory to Play's recomendation of using Jdk 6 or above. Notifying Play Google Groups about this.
I was getting the same error while trying to build using sbt-launcher.jar which was invoked through jenkins. In my case there were two Scala versions within ~/.sbt/boot/ and removing the older version solved the issue.
I was trying to setup my development environment for one of our projects when I hit this issue. The problem was the sbt.version parameter in the build.properties file of our project which specifically mentioned the version of sbt as 0.13.8 and I had sbt 0.13.11.
After removing sbt 0.13.11 and installing 0.13.8, the issue got resolved. Or if it is possible for you to change the sbt version in your build.properties file, you can do that as well.