SBT eclipse command issue on multi-project - eclipse

I imported an eclipse project from an sbt multi project.
The sbt eclipse command did complete normally
But the resulting eclipse project is full of errors as dependency between sub projects are not seen.
I think the sbt plugin is failing on multi projects, or am I missing something.
The project run from sbt runs flawlessly.
But I have no IDE support.
I tried Idea, the multiproject loads flawlessly, but the type indication on flyover is super slow and very often freeze Idea, it is unusable.
Eclipse as tons of errors because of depencies, but for the type recognised, it gives them very quickly.
I hope somebody has a solution.

I guess that you must run "sbt eclipse" from the root sbt project directoy, and then, when importing into eclipse, click the checkbox "search for nested proyects". That will create a separate proyect for any of the multiple sbt subprojects. And the references between them will be found.

Related

How do I handle MANIFEST.MF with sbt and Intellij?

I'm writing an application in Scala using IntelliJ and sbt (latest stable version on everything).
I can run and debug it just fine from within intellij but if I try to run the standalone artifact it complains that it can't find Main and I should add a MANIFEST.MF file in META-INF. If I add this manually to the jar, it runs fine. But if I add this to my source tree to be automatically included inn the jar, the program won't start in Intellij because 'duplicate MANIFEST.MF' and there isn't any one else. So I assume Intellij adds one on it's own.
I've tried all the tricks I've found regarding mergestrategy with no luck.
What is the correct this?

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

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.

How to log commands issued from Intellij with Scala plugin to SBT

I worked some time with SBT and a text editor. Then, moved to Intellij, installed Scala plugin, and created a new project as in the picture here by choosing it to be based on SBT. Also, in the settings, I chose the SBT launcher to be custom, and made it point to the already-installed sbt.
I believe Intellij is probably calling SBT commands like sbt run and stuff in the background. My question: How can I see (a log of) these commands as they're called by Intellij to sbt and their responses? And as a plus: where can I edit them? I opened the "Edit Configurations" but couldn't find anything like sbt compile.
I believe Intellij shows the responses (e.g., [info] downloading...) below in the "Background Tasks", but
1. It doesn't log these responses and
2. It doesn't show the commands issued by Intellij to sbt.
Big picture/what I'd really want to do: have the IntelliSense features from Intellij and Scala plugin, but build and run from the terminal and not have any effects from Intellij on that.
The IntelliJ Scala plugin doesn't (yet) call sbt except for project import/refresh or if you have a run configuration that uses sbt. Compilation is done by the built-in compile server. If you prefer to use IntelliJ as an editor and run tasks from the sbt console, that usually works fine.
I don't understand the question well
do u want to see the SBT output? if you are using run/debug you will see both the command & the output in the run window (alt+4)
also intelliJ has a window called event log
I hope that help
Intellij reads the projects configuration from sbt and creates an equivalent configurations for its project format (either .idea folder or .ipr)
this is a similar question to yours but about maven, you may find helpful:
https://stackoverflow.com/a/30167052/2675679

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.

ClassNotFoundException when running JUnit unit tests within Eclipse (using Maven)

I have just upgraded my SpringSource Tools Suite (STS, a variant IDE of Eclipse) to the latest version (v3.6.1). Then all my JUnit unit tests can not be run again. I am getting this error:
Class not found ClassToTest
java.lang.ClassNotFoundException: ClassToTest
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
According to this blog:
ClassNotFoundException when running JUnit unit tests within Eclipse (using Maven),
it is because of some misconfiguration of Maven plugin in Eclipse. However, in STS 3.6.2 I cannot find this option "Include Modules" in the Maven plugin. How can I fix this problem and re-enable my unit tests?
There are still some back-draws on the current m2e plugin. Unit-test-cases couldn't be run as their including project grouped in a working-set. Following may help:
Right click on project including junit-tests.
Select Maven -> Disable Workspace Resolution
Try then to run your test again.
OK it seems I'll have to answer this question by myself.
The main reason for this problem is still the m2eclipse eclipse plug-in. The new version of this plugin does not support nested modules in one project. If we really need to see multiple modules we have to remove the old one from the package explorer and create a working set and import the project again using the option "import existing maven projects". The eclipse import wizard will pop up a window and ask you which module to be imported. Then we can select all the modules and finish the import. As a result the working set will contain all the modules of your project and treat each module as a separate project, although in the workspace your modules are still in one project. By doing this it resolves all the problems that I have come across in Eclipse related to classpath, such as not being able to search a class or not being able to run the unit tests and get a java.lang.ClassNotFoundException.
For reference, here is an article to teach you how to create a working set:
Working set
I think you can import the project without creating a new working set but the working set will keep all the modules that belong to your project in one set so it is easier to organize.
I wish I had the answer two months ago so I wouldn't have spent much time searching for a solution.
I think I have found the solution, at least this worked for me:
right click on the project and choose 'Maven' -> 'Update Dependencies'
Then when I tried , I did not get ClassNotFoundException .
I tried everything mentioned here and in other posts. Some of the solutions that people proffered were:
Change the output folder for the test classes.
Create a custom builder for the project that would run test-compile from Maven.
Move the Maven dependencies higher in the Order and Export list in the project build path.
There were many, many more but the one that I found to work was as follows:
Close the development environment.
Delete the jars used by the project from my local Maven repository.
Open the IDE.
Build the project.
Run the test.
After hours of beating my head against my keyboard and following suggested solutions, this one worked!
We too faced the same ClassNotFoundException while trying to run JUnit test class. But when we tried using the following steps, it successfully started running.
Select your project.
Click on the project option displayed in toolbar in the eclipse IDE.
Select “clean”.
Now try running the test file.
As a work-around, try running mvn test-compile (either in Eclipse or from the command line), then try running the Junit test within Eclipse.