Scala-SBT - How can I remove all 'class not found' issues in imported project in IntelliJ IDEA - scala

I am new to IntelliJ IDEA. I am importing my Scala-SBT project for the first time.
After import, it showing lot of Class Not Found problems. But in IntelliJ SBT console, clean, update, compile everything working fine. Because it is not a startup project, it is running project, lot of other people are already working.
Now, clone seperately and imported as local Scala SBT project still it not recognising my dependenty jar. Still, Class Not Found in all classes.
But I don't know, how to make automatically consider my dependencies from by build.sbt.
Also should I need to import in project settings as third party jars?

Check if there is no errors during import. If they are disable "download source" checkbox in project import settings.
You can always reimport project in IntelliJ from SBT panel

I found solution finally,
I imported as Scala SBT project and i selected build.sbt file in the root folder instead of project root folder.
Downloaded exact Scala version of my project and put in project settings.
Refresh Project - It downloaded all needed jars and took 15mins to complete.
Anyway, All class not found errors thank God.

Related

Intellij: Not a valid project ID:

I updated Intellij Idea to 2018.2.6
Now I can not start my Play-Project with a Play-Configuration - it gives me this:
[error] Not a valid project ID: myProject
[error] project myProject
[error] ^
I tried all of these proposals:
https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000530510-SBT-Shell-Error-Not-a-valid-key-idea-shell?flash_digest=650678ba2e9ae36479f2c3e0ab460379a393d2ce
A plain SBT configuration works.
I could solve the problem:
Close Project in Intellij.
Delete .idea folder of the Project.
Open the Project again.
In my case, the reimporting of sbt project fixed the issue. This can be done by clicking on the "sbt" tab on the right pane, right-click on the project and selecting "Reimport sbt Project".
Using IntelliJ Idea Ultimate 2020.2 none of the above worked for me.
I had to
Delete the .idea folder
Restart IntelliJ
File -> Project Structure
Create a new play module at the same location
I had a variation of this, which is probably not that common, but I mention it just in case someone encounters the same thing.
We have a Play2 project wrapped in a larger Maven based project. Surprisingly IntelliJ actually imports this quite well, and it basically works running it as a Play2 application within that larger project.
However some time ago I reimported the entire project and I used the Maven import option to "Keep project files in:", and put them outside the project directory structure. So now all the .iml files are in another directory. But when this was the case the sbt runner would try to load the project from that directory, and of course it couldn't find my project file any longer with the same error as given in the original question.
The solution in this case is that the Intellij .iml file must be in the same directory as your Play2 application.

Intellij not picking dependencies from .ivy2 cache folder

I am using Intellij for scala project. I am using babun application for compiling/running/creating assembly jar for my project because in my organization, we can't use maven artifact repository and we have our own for downloading dependencies so I had setup proxy for it in babun(could not see such option for windows command application). Through babun, I downloaded all dependencies as defined in build.sbt and it got downloaded in <USER_DIRECTORY>/.ivy2/cache
Somehow, when I Synchronize my project in Intellij, it doesn't show up any dependencies(under Project Structure->Project Settings->Modules->Dependencies tab) and I get error in my code for all classes that are coming from dependency jars. It was working fine before but IDK what I did wrong suddenly :(
I also tried setting up VM argument Dsbt.ivy.home= but no help.
Also followed article - Changing Ivy Cache Location for sbt projects in IntelliJ IDEA?

IntelliJ - use imported modules as dependencies like maven projects in Eclipse

I've been asking myself this question for a couple of years but never really found the solution.
I used to work with eclipse (on maven java projects). I could import a project -let's call it 'proj-A'- and if one of proj-A's dependencies was found in the workspace with the same exact version, eclipse would use that project's source instead of the jar from the repository. This way I could edit a library and see the changes in the project that used it right away.
For example, in Eclipse, if proj-A depended on dep-B-1.2.3-SNAPSHOT, I could import proj-A and dep-B in the same workspace, and if dep-B version was 1.2.3-SNAPSHOT I could see the live changes in dep-B sources from proj-A classes.
I'm now working in scala in IntelliJ. I don't seem to be able to do that. what's the best workflow if you want to avoid publishing the library and then reloading the whole project that uses it along with all its dependencies every time?
If I import proj-A as sbt project I can find dep-B snapshot jar in the libraries (loaded from some repo, be it local or remote), and I can't see the code changes to the dep-B module imported in the same intellij project (i.e. the equivalent of eclispe workspace).
If I manually remove the dep-B jar and add the dep-B module as a dependency for proj-A I'm forced to do it everytime I reimport proj-A for some reason.
I'm not sure there's a way of doing this as straightforward as the eclipse way (automatic), but maybe you know something I don't ...
thanks
It should work out of box for dependencies, which are imported to the project as modules, no additional settings needed. At least for Java.
Just do not run a Maven goal, that would use dependencies from the repository.

Scala IDE 4.0.0 thinks there's errors in an out-of-the-box Play Framework 2.3.7 program

I've created a Play Framework program via Typesafe Activator (so it follows the template exactly).
I used sbteclipse-plugin version 3.0.0 to create an Eclipse project and imported that into Scala IDE 4.0.0. These are all the latest versions at the time of writing.
The Scala IDE definitely seems to support the Play Framework. It has syntax highlighting for the custom formats, including the routing file and templates. Yet, it doesn't seem to be able to find the views from the controllers. In particular, the call to views.html.index triggers an error: "object index is not a member of package views.html".
I tried enabling refreshing using native hooks or pooling as detailed here, but it had no affect.
I should note that while the code has been compiled in the command line (with activator ~run), it hasn't been compiled in Scala IDE, since I don't know how to (it doesn't seem to be documented anywhere).
What can I do to get rid of these false errors?
EDIT: After running activator clean ~run, I have another error: The project cannot be built until build path errors are resolved. There's no further details on what these build path errors are.
Update: Just upgrade to sbteclipse version 5.1.0 and everything should work out of the box. Also make sure you follow the Play documentation on how to set up Eclipse/ScalaIDE.
This is a known bug in sbteclipse, which probably will be fixed soon.
For now, you can add the following line to your build.sbt:
EclipseKeys.createSrc := EclipseCreateSrc.All
Kill the SBT console and run sbt eclipse again. That should add the following line to the .classpath file within your project folder as a workaround:
<classpathentry kind="src" path="target/scala-2.11/twirl/main"/>
Refresh your Eclipse project to pick up the change.
I had the same issue, also with Scala IDE 4.0.0 . I followed mkurz instuctions and they worked like a charm. But instead of changing the .classpath file in the project folder manually I used Eclipse interface:
In the top menu of the main window, click on Project and then on Properties.
In the Properties window, click on Java Build Path option (options list is on the left)
In the Source tab, click on Add Folder... button.
In the Source Folder Selection window, choose the target/scala-2.11/twirl/main folder, so it is included in the compilation path. Click Ok button.
Click Ok in the Properties window.
Now the project should compile just fine :) . With that I was able to finish the play setup example in Scala IDE website
I tried #mkurz solution first, but also ran into the same error as #matt. I became frustrated that I could not generate the eclipse project without having to go to the Eclipse project properties to manually fix the build errors. After some investigation, I discovered the solution that removed all errors entirely. Add this your build.sbt:
unmanagedSourceDirectories in Compile <+= twirlCompileTemplates.target
Or if that does not work for you, you could also use:
unmanagedSourceDirectories in Compile <+= target.zipWith(scalaBinaryVersion) { (b,v) => b / s"scala-$v/twirl/main" }
Good bye, build errors!
I got the same error message.
Are you using java8 as jre in eclipse?
After switching back from java8 to java7, everything worked fine again.
If, after following Mkurz' instructions (adding EclipseKeys.CreateSrc... ), your problems are not solved, click on Project -> Properties -> Java Build Path. Look at the source folders tab.
You may find a duplicate file folder named .../src_managed/main (Thanks Matt). If so, close the project. Remove ONE of the two ../src_managed/main entries from the .classpath file (located in the base of the activator/SBT project directory). Reopen and clean the project and you should be good to go.
For me, it turned out that installed JRE in the Scala IDE was openjdk, changed it to Oracle Java 8 and it worked.

How to make Intellij follow sbt GitHub dependencies?

I managed how to add github dependencies to my sbt project following the instructions in this link.
However, Intellij could not find the github dependencies.
After om-nom-nom sugestion, only Scala plugin is needed:
Installing the Scala plugin from a fresh idea install
Import project from external model -> SBT project
? use auto import ?
Register "unregistered Vcs root"
Set module SDK with your JDK folder and adopt it for the project
Write a main file and press ctrl+shift+F10
The step 4 is important because you won't need to keep the working copies of the sub-projects anymore.
Idea creates them inside ~/.IdeaIC13 folder.
This link talks about multi-root Projects and synchronous branch control.
ps. the SBT plugin somehow was disabled and ideia became cofused about a subproject with a (nested) subsubproject.