sbt Project name must be valid Scala identifier error while creating new project - scala

I wanted to create a new project in scala in intellij. I have chosen Lightbend Project Starter and then Akka Quickstart Scala. On finish I got this error:
sbt Project name must be valid Scala identifier
The name of my project is "akka-demo" but "akkademo" and default "untitled" don't work either. Empty catalog is created. Same with other templates. How can I overcome this?
Env:
Intellij idea ultimate 18.3.4
sbt 1.2.6

As mentioned, akkademo should indeed work.
It sounds like an IntelliJ problem.
If a project directory was created, you can try to remove the .idea directory and reimport the project.
Furthermore, you can download the Akka Quickstart Scala project from Lightbend's website, and start the sbt shell in this directory.
Try to run and compile to make sure your environment is set up correctly.
If everything works with the sbt shell but not in IntelliJ, then open:
IntelliJ -> Preferences -> Build, Execution, Deployment -> Build Tools -> sbt and check the Use sbt shell for imports and for builds.
Then go to the sbt tab in IntelliJ and refresh.

Related

sbt dependency root catalog differs from intellij libraries after import

I'm using Scala plugin version 1.3.3 for Intellij 14.0.3 at my work computer and have started a new SBT project from scratch without any hassle.
But my problems starts right here where build.sbt file have compile errors in Intellij, it can not resolve any line of code. I can how ever auto import by changing the build.sbt file and adding a library dependencies..
So I tested to add scalatest which is downloaded to an .ivy2 directory, but a totaly different one that Intellij are using.
This is how ever how my project structure are looking like, every libs have an error due to wrong path.
And here is where SBT plugin is locating all of it's dependencies and scala libs.
I know how to change where .ivy2 directory will be stored by adding these two parameters to
Settings -> Build,Execution, Deployment -> Build Tools -> SBT -> JVM Options -> VM parameters
-Dsbt.ivy.home=c:/.ivy2
-Dsbt.home=c:/.ivy2
But it only works for .iv2 folders and not the .sbt folders that are also in the wrong place. I believe that's the cause of why I can't resolve the symbols in the build.sbt script.
Does anyone know why this is happening and how I just can have one directory for both Scala plugin and Itellij project files?

Intellij unable to resolve references to a specific jar file

In a given project that is driven by sbt there is some kind of corruption in the project libraries specifically for a MavenLocal repository used for kafka-spark-9.7.2.jar in which:
references to the classes provided by that jar are marked as "symbol not found" by the editor parser
however the editor (strangely) does offer to import the classes
but after accepting the import, the symbols are still marked in red as unresolved.
The following attempts to "clean things up" have already been performed:
Build | Make Project
Build | Rebuild Project
In addition I have verified that the project does build from
sbt package
on the command line
UPDATE After re-running sbt gen-idea the librraries are still not found by the Parser. yet the libraries exist -even IJ knows about them as shown in the following screenshot. Why is it that IJ can find the library
C:\Users\S80035683\.ivy2\cache\org.apache.kafka\kafka\jars\kafka-0.7.2-spark.jar!\kafka\api\FetchRequest.class
However IJ is unable to resolve any classes from that library in the Parser?
You have to build the project for Intellij, try to do this in your project root:
sbt idea with-sources=yes
This should build the project structure from scratch and add the right dependencies, usually I refresh the project after adding a dependency or a jar.
Edit:
To use the command you need this plugin, otherwise you can use gen-idea but I used it only a few times and I'm not sure how it will work out.
Edit2:
There was some confusion, first, for the IDEA SBT console you don't need to prepend the sbt command since you already are inside sbt:
If you have the sbt plugin for idea you can use gen-idea with-source=yes (without prepending sbt)
From the terminal, either you go to your project root and type sbt to enter the sbt console and use gen-idea or idea with-sources=yes (without prepending sbt)
or directly sbt gen-idea or if you have the plugin sbt idea with-sources=yes (prepending sbt)
To reach the sbt console inside idea you need to install the sbt plugin on preferences -> plugin and search for sbt and then View -> Tool Windows -> SBT Console:
To start the console click on the play button, to kill the console on the skull.
I had the same problem. I fixed it by directly writing the CLASSES and SOURCES of the problematic library. This can be found in .idea/libraries/SBT__<problematic library>_jar.xml

sbt eclipse command changed files and packages

I created a new Scala project in eclipse then added a package and Scala object ,
So far so good ...
i want to add external library so i added a project folder with build.properties plugins.sbt files,and another file build.sbt in the root project.
in the terminal i compiled successfully the project with the sbt compile task.
the problem is that after sbt eclipse command the eclipse project changed from Scala project to something else.... all the packages changed to simple folders and the Scala project is ruined
scala IDE :Build id: 3.0.3-20140327-1716-Typesafe
scala version :2.10.4
sbt version:0.13.0
you can see in the image
Where did you get the eclipse command from? I'm guessing you're using sbteclipse.
I created a new Scala project in eclipse then added a package and Scala object , So far so good ...
If I understand correctly, this is exactly the opposite of what the plugin is intended to do. I think you're suppose to create a plain sbt project, and then let the plugin generate the Eclipse project.

Editing Build.scala in Intellij

I want to migrate our build from maven to SBT, so now I work separatedly on Build.scala file. However I don't benefit from any syntax highlighting (that is quite obvious, I don't have SBT in my classpath). What is the correct way to get SBT to my classpath, adding sbt-launch.jar does not seem to help.
IntelliJ 13 has built-in SBT support; if you're running a lower version, then you can have a look at their sbt plugin.
There's also an sbt plugin on github for generating idea project files. I've had success with running the gen-idea task it provides.
Run sbt gen-idea. It will create a "YOUR_PROJECT_NAME - build" project within your main project (for whatever your YOUR_PROJECT_NAME happens to be). Under the project folder of the build project, I was able to write a Build.scala with the following code:
import sbt._
object Build extends Build {
}
The SBT Build trait is recognized just fine. I'm running IntelliJ 13 build #IU-133-696, Scala plugin 0.30.378.
Eventually what I did is finished to write my build.sbt stub, and opened a project with it. Now everything seem to work.

Unable to make IntelliJ Idea 12 work with Scala compiler

I have installed Scala, sbt, eclipse and IntelliJ Idea 12. And also jdk, jre, etc. I'm able to run scala in Eclipse (Scala eclipse IDE) but I can't do it in Idea, even though I downloaded and installed scala plugin though Idea. Here is what I'm having at File -> Setting
and at a new project creation page
How do I solve these issues?
whereis scala
scala: /usr/bin/scala /usr/bin/X11/scala /usr/share/scala
which scala
/usr/bin/scala
I know I'm repeating this at any possible occasion—but your life will be much easier if you have sbt generate your IDEA project instead of trying to set it up manually. That will take care of configuring the modules correctly, so you are instantly ready to compile and run.
Here is a blog entry that might help. The section "How can I integrate libraries installed by SBT to IDEA?" tells you how to generate the project files.
Basically you need to create—starting from the root directory of your project—the file project/plugins.sbt with the following content:
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.4.0")
(you can also do that in the file ~/.sbt/plugins/build.sbt instead, that way you have the plugin available for any of your projects)
Then you run sbt gen-idea, and afterwards you can open the project directly from IDEA through File -> Open Project (and pointing to the project's root directory).
You could also generate your IDEA project with Gradle, which handles Scala+IDEA combination very well. Here's a minimal build.gradle script to do this:
apply plugin: 'scala'
apply plugin: 'idea'
repositories {
mavenCentral()
}
dependencies {
compile 'org.scala-lang:scala-library:2.10.1'
}
Just create a directory for your project, put build.gradle inside it, create src/main/scala subdirectory, then install Gradle and run gradle idea inside your project's directory. That should generate nicely configured IDEA project. With this method you don't even need to install Scala.
What exactly your problem is? I don't see anything on your screens which prevents you from using Scala in IDEA. Just select "Set Scala Home" radiobutton in "New project" dialog and then select your Scala installation path (I guess it will be /usr/share/scala). IDEA then will automatically create library and compiler libraries and add Scala facet to your project.