IDEA says a dependency is missing, SBT disagrees - scala

my issue seems similar to Getting IntelliJ IDEA understand SBT dependencies
except I'm using sbt 1.4.4 ,and the plugin suggested in that question no longer appears to work (it requires sbt version 0.13.x, and last commit to that plugin was 7 years ago)
is there anything similar that might work with more recent versions of sbt, or some other way to get intelliJ to work?
It only seems to affect 2 dependencies, all other dependencies works fine, thing is, i really need those 2 dependencies.
I'm on Linux, should it matter, a colleague opened the same code on Mac, and had no issues, however I've tried clearing every cache i could think of, reinstalled IDEA, rebooted twice, changed idea settings to use sbt shell for everything, nothing and everything in between. I've tried to rebuild with sbt version override enabled and/or disabled.
I dont get any errors from intelliJ rebuilding the project, but the editor still insists that some dependencies does not exist!
I'm out of ideas, how can I fix IDEA?

First identify the path to problematic dependencies by executing
sbt 'show dependencyClasspath'
which prints out something like
Attributed(/home/picard/.cache/coursier/v1/https/repo1.maven.org/maven2/org/typelevel/mouse_2.13/1.0.0/mouse_2.13-1.0.0.jar)
Next in the following order
sbt clean the project
invalidate caches
Exit IntelliJ
nuke your project's .idea directory.
Now say mouse was the problematic dependency, then remove it with
rm -fr /home/picard/.cache/coursier/v1/https/repo1.maven.org/maven2/org/typelevel/mouse_2.13
Finally reimport the sbt project which, if you have the shortcut setup, from project's root directory
idea .
and let sbt refetch the missing dependencies and let IntelliJ reindex them.

Related

Why is my SBT intelliJ build not including dependency Jars?

My SBT appears to have stopped including dependency Jars. I have been able to do this previously, until I decided to upgrade my intelliJ version, which messed my whole environment. I have since reverted back to the old version, but I still don't see why this is happening.
By build.sbt looks fine, and downloads all the dependencies i ask for. My assebmbly.sbt is also on point.
`resolvers += Resolver.url("sbt-plugin-releases-scalasbt", url("http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/"))
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2")
`
I am trying to build a fat jar. When I do a build artifact now, it just builds a jar, but without the dependencies.
I'm new to IntelliJ and SBT, so I am not adept in the way they work. How do I get around this problem? Thanks in advance.
Have we guess which versions you are using. The recent one is sbt.version=0.13.9 set in \project\build.properties".
The resolver statement could be overdone.
Try your build file with the command line. (E.g. In IntelliJ Terminal window, by entering sbt )
Invalidate cache / restart ?
I ended up having to uninstall and Reinstall IntelliJ and deleting all the old configurations. My Jar builds fine now.

How to fully clean, re-resolve and rebuild a Scala sbt-managed project in IDEA?

TL;DR: How can I fully reconcile all dependencies in IntelliJ when SBT file changes
I have a SBT project setup in IntelliJ. For the most part if works like a charm, but it is quite a pain for me, to change the version of the dependencies and compilers.
What I hope to do, is to update my SBT file, and click something like clean project in IntelliJ, so it gets up to date.
The best menu item I have found is Rebuild project. It reads new dependencies, but keeps the old ones around, so External Libraries contains multiple versions of the Scala runtime and 3rd party libraries.
To get around this I can close IntelliJ and delete all files in .idea/libraries. When I restart IntelliJ it will re-resolve the dependencies. It works, but manually deleting metadata files indicates that I am doing the wrong thing.
To refresh IntelliJ after changes made in *.sbt files:
Open the SBT Project pane (Menu View / Tool WIndows / SBT)
Right click on your SBT project
Select Refresh external project
When you save the SBT file, IntelliJ IDEA normally refreshes the project. But if it doesn't, you can do it manually.
There is a Refresh All SBT Projects button in the SBT Panel:
On the occasion that IDEA is still confused, not finding packages you just added:
From the File menu:
It's a pretty big hammer, requiring a restart of the app, and multi-minute rebuild of the IntelliSense index. But it's occasionally the only thing that will get IDEA to recognize your new SBT packages.
try following steps:
close IntelliJ
backup whole project folder
delete .idea folder
delete target folder
delete project/target folder
reopen IntelliJ and import as a sbt project
Note this is only for SBT projects
Another heavy hammer but seems to work.
Close IntelliJ
Delete .idea folder
Import app from existing sources
Has happened to me before, and yes, is a PITA.
What I usually do is to manually remove the dependencies from the project, all of them, then let sbt re-import what is actually needed. Don't do it on the UI though, since even having multiple selection, will ask for confirmation for EVERY dependency! (you will be clicking "Yes, I'm sure" for an hour), instead, go and delete directly from the .iml project file on your .idea/modules directory.
I was using different versions of sbt and scala across different proejcts and IntelJi got confused somehow. I am only able to resolve the issue by removing the sbt and ivy2 cache folders:
rm -rf ~/.ivy2
rm -rf ~/.sbt
Agree, that's a PITA. Nothing helped me (I tried "Invalidate/Restart", removing files from ".idea/libraries" and restarting).
The only way to overcome the problem for me was to manually remove project-related folders from the IntelliJIdea cache. I removed these folders from the following places (I use OSX and IntelliJ-Idea 14):
/Users/{UserName}/Library/Caches/IntelliJIdea14/compiler/{ProjectName}
/Users/{UserName}/Library/Caches/IntelliJIdea14/compile-server/{ProjectName}
This helped me, hope it will save time for someone.
If you are using the activator through a terminal/shell/command prompt use the following command:
activator clean
Or just "clean" on the sbt shell through intellij
It should help reset things and next time you run or compile, it should go through it from scratch.
IDEA 2016.2.4
None of these solutions worked for me.
**** BEFORE YOU TRY THE ANY OF ABOVE. MAKE A BACKUP OF THE SBT / IDEA PROJECT IN QUESTION *****
If I updated the 'build.sbt' then the external library dependencies on the project view did not update. Moreover, the Project Structure still showed the old dependencies. No matter what I tried IDEA would not refresh.
The only way I could get a partial restore was to copy the '.idea' folder from another machine. SBT plugin implementation is ****ed! I removed the '.idea/libraries' folder beforehand and then IDEA did not restore this folder. I tried many times importing the project again.
Very bad
:(
ADDENDUM: I managed to get my project working. I think SBT with IDEA is no longer at fault entirely. It could be just possible that my Apache Ivy 2 cache might have been corrupted. So I executed the following commands:
$ rm -rf ~/.ivy2/cache/org.scalatest/scalatest_2.11/*
$ rm -rf ~/.ivy2/cache/org.scalactic/scalactic_2.11/*
Restarted IDEA with invalidate cache under the file drop down menu item. This seemed to trigger some internal action in IDEA and SBT. I also tried manually adding add JARs throught the IDE, but it got massively confused. Moral of the story is to work on two different laptops machines daily and keep them updated.
Also double check SBT from the command line works. I was using 0.13.12
$ sbt about
$ sbt clean
$ sbt test
Also recheck with the SBT dependencies plugin too.
What worked for me was to:
1) Close IntelliJ
2) delete .idea/libraries internals
3) Start IntelliJ
4) right-clicked pom.xml Maven > Reimport
After that there were no old versions and duplicate libraries in the External Libraries.

Why does IDEA report errors for build.sbt in a new sbt project?

I'm running IntelliJ 13.1.5 community edition. I've got JDK, Scala, SBT installed. The JAVA_HOME, JDK_HOME, SCALA_HOME and SBT_HOME variables are set. If I create a new SBT project, after initial sbt refresh, I get this:
The thing compiles and runs fine, even if I add dependencies, but the file itself shows tonnes of errors. F4 settings show empty SBT module stuff:
I then installed https://github.com/mpeltonen/sbt-idea and ran sbt gen-idea in the project folder. This created a bunch of files, and reloading the project, the reds in the sbt file went away.
This is on my laptop. However, on my work machine, simply creating a new project works fine, and the sbt file isn't filled with red. Can't seem to figure out how that machine's different. Any pointers on how to resolve this annoying issue?
In case IntelliJ IDEA struggles a bit with caching, try the first and if still not working the second should definitely do the trick:
File -> Invalidate cache and restart
Close IDEA, delete .idea, re-import your project
I was also getting highlighted errors in all of the build.sbt file.
What fixed it was to select to Download "Sources for SBT and plugins" in the Import Project from SBT window.
Please, check if you added the “scala-library*.jar” to Scala compiler library
This link might be helpful:
http://blog.jetbrains.com/scala/2010/09/02/project-configuration-explained/
If you are using windows or linux, please also see:
http://confluence.jetbrains.com/display/SCA/Setting+up+Scala+plugin+project+in+IntelliJ+IDEA
Update on 2020, Apr
This works for scala 2.13 and Intellij 2020.1 when:
sbt files has error
project structure is wrong
Reason is 'External libraries' from sbt is not loading for IDE.
To do so, similar to old version: https://www.lagomframework.com/documentation/1.6.x/java/IntellijSbtJava.html
1. rm -rf .ida
2. Click Menu item: Open... to pick the project directory
If not working, I assume you need to setup Global SDK for intellij by
cmd+; and pick the path of scala.
In case of mac,
brew install scala normally echo out the path /usr/local/opt/scala/idea
Let ide browse to this path by holding cmd+shift+G to open path.
IDE should find the path like /usr/local/Cellar/scala/2.13.1/idea/lib/scala-library.jar and scala-compiler.jar and scala-reflect.jar
There might be better way to do the global scala setting though.

IntelliJ show errors in scala source files but the project compiles successfully

I'm working with project in intellij IDEA IDE based in maven. I can perform all maven goals but IntelliJ is showing a lot of errors in the source code like bellow:
Everything worked fine a few hours ago. I don't understand why the IDE continue
showing errors. When I rebuild or compile the entire project (CTRL + F9) or a single
scala class I always receive a success message like that:
I already had configured scala plugin before, so I don't know what is happen.
thanks for your help
Sometimes the IntelliJ cache gets corrupted. You can fix this by the following:
File > "Invalidate Caches / Restart"
After choosing "Invalidate and Restart" when prompted, IntelliJ will restart and rebuild its cache.
If IDEA has lost track of obviously correct types such as Database or DateTime it probably means the configuration of the project is wrong or corrupted. Most commonly it does not have the required 3rd part dependencies such as Joda Time.
If you're not already doing so, define your project solely in SBT and use the sbt-idea plug-in to produce your IDEA project definition. Then whenever you change the project dependencies, re-run gen-idea to regenerate your IDEA project files. No muss, no fuss.
There are many bugs raised in jetbrains's bug tracker for this. I suggest you raise some bugs or vote for existing ones.
It loos like the problem you have is with the type aware highlighting which is worse than useless.
thanks for your responses.
I solved this problem importing the project again.

IntelliJ IDEA Scala plugin's syntax highlighting displays Scala packages in red

This is a bit weird, I've got IntelliJ IDEA 10, a fairly recent Scala plugin on it and sbt 0.7.7. I've been using the same setup on the same project for a while and syntax highlighting worked perfect.
After a few clean/compiles from sbt (I'm not really sure about the action), everything from Scala._ is red. For instance, List() is red but when I import scala.collection._ it gets fixed. The project compiles without any problems in both IDEA and SBT. What may be the problem?
(new/other projects are OK on the same setup so I guess I've messed up something but I have no clue where to look for it)
Thanks
I've never found a single solution to this, so i generally try all the things.
sbt gen-idea (to recreate IDEA project meta-data)
File > Invalidate Caches ... > Invalidate and Restart
After invalidating caches, upon restart IDEA will re-index all of your class files.
Usually I'll try
sbt> clean
sbt> gen-idea
Then if it didn't work go for invalidating caches. If that still doesn't work (and it almost always does) try deleting the following directories and then perform #1/#2 from above again:
target
project/target
.idea
.idea_modules
at project Settings, add the jars to its dependencies of IDE, then you will get the red away.
SBT is one thing, IDEA is another, they use their own way to compile scala. some sbt plugin for idea is also something that just hook sbt command line to idea's panel.
This sometimes happens to me when the SBT and IDEA projects get out of sync. Simply run the SBT Idea processor again - this regenerates your Idea project files.