IntelliJ Scala "Package" not in "New" menu - scala

I am using IntelliJ and would like to create a new Scala Package. In all of the instructions that I find online I see that I am supposed to select "Package" from the "New" menu. However, my "New" menu does not include "Package" as an option.
How can I add "Package" to this list or otherwise add a package to my Scala application?
Also as a side note, I am developing Scala applications and as such I would like for primarily Scala related templates to appear in this list as opposed to the menagerie or irrelevant templates that currently presents itself. How can I edit the list of templates that appears in this menu?

I solved this problem by taking the following steps:
Making sure to install both the Scala and SBT plugins. (I was missing the SBT plugin)
Copying all the source files (*.scala) into a temporary location
Deleting the project.
Creating a new project with the same structure and copying the source files into their proper location.
Now "Package" appears in the menu (and full syntax hilighting now works, which was the reason why I wanted to fix this in the first place). Note that simply installing the SBT plugin (step 1) was not sufficient in fix this problem.
Maybe it was a bug.

Related

Why does IntelliJ seem to import my scala libraries twice?

I have just started trying to use Scala with IntelliJ. I created a new project as per the instructions in:
https://docs.scala-lang.org/getting-started-intellij-track/getting-started-with-scala-in-intellij.html
I installed scala 2.12.6 using Homebrew and selected that when creating my new Scala project in IntelliJ.
For some reason, under External Libraries, I have every jar inside the scala installation twice:
I created a hello world and when I try to run it, I get this error:
Error:scalac: Multiple 'scala-library*.jar' files (scala-library.jar, scala-library.jar) in Scala compiler classpath in Scala SDK scala-sdk-2.12.6
However inside the Scala libraries folder there is only one jar of each.
I'm not sure what I'm doing wrong here. I've tried other versions of Scala, but got the same results. I tried to delete one of the jars, and deleted the actual only copy of it and I had to reinstall scala.
#Zapatilla,
Follow this,
Click File --> Project Structure; Select Modules; Select Dependencies
You should see scala-sdk-2.12.6 there. Remove it by selecting it first and then clicking the "-" sign below.
Once done click the "+" button and select "2. Library --> Scala from SDK"; Select the appropriate version and hit Apply;Ok.
This should resolve it.
I just found the problem. When I right click on the library in the project explorer, I saw the paths for each jar file. It seems like in the scala installation by homebrew made in /usr/local/Cellar/scala/<version> there are two folders that contain the same jars:
/usr/local/Cellar/scala/<version>/idea/lib
and
/usr/local/Cellar/scala/<version>/libexec/lib
Since I was importing in IntelliJ this path /usr/local/Cellar/scala/<version>, all jars from both folders were imported, causing the duplication.
Solution is to import just one of those two options. I have now set up IntelliJ to just use as external libraries /usr/local/Cellar/scala/<version>/idea/lib and it seems to work!
I am using windows & intelliJ combination, I faced the same issue since i am new to scala, as usual i was searching in google and spend much time in resolving my issue.
Most of the suggestions are for linux based, please try the below, in my case it worked out.
1) Check your iml file and verify the orderEntry. By default if you download sbt, it would contain 2 set of libraries. I downloaded the SBT version 1.2.7, it by default contain 2 set of libraries. one with 2.12.0 and another with 2.12.7.
2) The project iml file of mine had with scala SDK 2.12.0 which was the reason for my issues, I edited that to change to 2.12.7 which automatically changed the order with 2.12.7 first and solved my issue.
This solved my problem.

How I can create a scala application in InteliJ and create a scala clas(Ubuntu) ?

Hi i want to create a first little application with scala in InteliJ. My System is Ubuntu.
I install the Scala Plugin and create a new Project (Scala -> SBT )but if I want add a scala class I dont see this option :(
I think i need the scala sdk but where and how i bind them. Why it doesnt install by the plugin :/
First, if you are going to use SBT, auto-import might be a good idea. Else, you would want to manually import (see SBT tool to the right) to produce a stable, usable project.
Second, you mostly don't need to add java classes on the project folder, which is for the build project itself. You should be seeing a src/main/scala folder there instead. Try refreshing the view (right click menu, synchronize)

How to eliminate error underlining in IntelliJ 14.0.3 for Play 2.3.7 application?

I am using IntelliJ IDEA 14.0.3 to develop a Play 2.3.7 application using the Scala 1.3.3 plugin.
The attached screenshot shows that IntelliJ underlines the parameter to a render method as invalid when, in fact, the system compiles and runs successfully both in IntelliJ and at the command line (using Activator):
Another user has reported this problem in IntelliJ when the view template file uses Scala-specific syntax (i.e. Form[formdata.ContactFormData]) while the controller uses Java-specific syntax (i.e. Form<formdata.ContactFormdata>). That is the case here as well.
The sources to illustrate this problem are available at: https://github.com/philipmjohnson/intellij-play-error-highlight-problem
Is this indeed a bug in IntelliJ or its Scala plugin? Are there any workarounds?
My team and I have this same issue, using Intellij 14.0.3, Scala 1.3.3 plugin and Play 2.3.8.
To workaround this I open File --> Project Structure, then click on "Modules" on the left side bar. Adding target/scala-2.11/src_managed/main to the sources eliminates these reverse routing underlines. Make sure that the root target directory is not in the excluded folders.
One thing to note however, is that Intellij seems to remove this from the sources from time to time, causing much annoyance...
The above solution works, but I think it might be useful to document a ripple effect: if you are using the Checkstyle plugin, then after adding those additional source root directories, Checkstyle will process those auto-generated Java files and (in all likelihood) raise a number of (spurious) warnings.
After fiddling around a bit, it appears the easiest way to get Checkstyle to skip those files is to specify the "Inspection Scope" as the "Default" version control scope. Since you will almost certainly exclude the target/ directory from version control, this parameter to Checkstyle keeps it on the straight and narrow. Here's a screen image illustrating the setting:

Eclipse Scala IDE: can't open hierarchy for standard library classes

I have exactly the same problem as in this question: Eclipse: Using "Open Declaration" ... in a Scala project
However, I'm using the latest Scala IDE in version 3.0.2 (I have downloaded the Eclipse bundle from the site), and I would assume such basic functionality works by now, and apparently it's me who have something misconfigured.
I have created a new Scala project. Then I open some standard library class/trait/whatever, let's say scala.util.parsing.combinator.JavaTokenParsers. The source is neatly displayed, but when I try to show class hierarchy, I get the message: The resource is not on the build path of a Java project.
Also, searching for references etc. won't work.
I guess it is a matter of properly configuring the build path? Or maybe I should somehow attach Scala library sources to my project? But I can see the source, so aren't they attached already?
Here is the snapshot of my project configuration:
UPDATE:
By playing a bit with setting/resetting build path stuff, I managed to get rid of pop-up warning but the class hierarchy comes up empty and when searching for references I get only hits from my own sources, nothing from standard library.
In another workspace I also tried randomly adding and removing scala-library jars and got it work almost, but the type hierarchy comes up only with super-classes, without any sub-classes (which renders it quite useless). Searching for references works ok though.
Funny thing, I cannot make it work in my original workspace...
Gotta love Eclipse.
Your build path is not configured properly.
If you take a look under Scala Library[...] you have scala-library.jar we can only see one top-level package scala. There should be numerous other packages besides that. (Ruled Out)
I would recommend you follow these steps
Right-click project, build-path, Java-build-path, Libraries and make sure that the correct library is referenced there.
If it is the one you need, Try to remove this library and add it again, then clean and re-fresh the project. Also try this step in a fresh workspace.(something must have messed up this workspace )
Lastly. Goto the path D:\Eclipse For Scala\configuration\org.eclipse.osgi\bundles\286\1\.cp\lib and verify the sizes of the jars there. There should be 6 jars there and the size of scala-library jar should be around 6.8M. If size is smaller, consider re-downloading

How to run scala code on Intellij Idea 11?

I am new to intellij idea and I decided to shift because I found the scala plugin on eclipse to be annoyingly buggy.
But, intellij idea, which I have heard to be very good, looks difficult to use.
I looked through the getting started with scala plugin page but couldn't find documentation specific to the latest version of lightweight ide of intellij idea 11 for scala.
I have created a project and made a hello world object in scala but I am not able to run it.
On trying to run it, it shows the scala interpreter (type in expressions to get them evaluated).
I don't exactly understand what changes to make in the project structure to be able to run scala code. As of now, i added the jsdk to point to my $JAVA_HOME and the scala library is also added. The scala plugin is also working in that syntax highlighting etc is fine.
The intellij idea user interface is also not very friendly and I don't get how to run the code. What modules am I supposed to add? Also, does compiled scala code run with jvm?
I'll be grateful to anyone who helps out.. I have been putting off writing scala code because I am not able to find THE IDE.
EDIT: Thanks for all the help! I am now able to run a basic scala program. I am trying to add external jars. What is the equivalent of doing Project right click-> Configure Build Path -> adding external jar files in eclipse? I tried adding "dependencies " under modules tab in project structure. It's adding the jar files but somehow the classes in the jar files are not still recognised.
With the Scala plugin installed either
A. Create a new project and select the Scala facet in the creation phase. It will create the Scala library lib and Scala compiler lib and setup the facet for you
B. If you already have a project. Go to Project Structure -> Modules and right click the module and go Add facet and add a Scala facet. Now you need to add scala-library.jar as a library of the module and go into the Scala facet and point it to a library containing scala-compiler.jar
Some more information
this is what your module should look like under project settings
select the Scala facet and this is what you should see (Library name for the compiler is unimportant as long as it says (version xxx) next to the library name
these are the jar files in my scala-compiler lib
and these are the jar files in my scala-library lib
With everything setup like that you should be able to right click -> new Scala class (Select object from the dropdown) in a source directory and add
def main(args:Array[String]) {
println("Hello world")
}
then right click on the class and select Run Classnam.main() and IntelliJ will setup a run configuration for you.
Edit: I can see someone posted somewhat the same I want to say here. I hope this can give a few more in-depths hints, so I will post it anyway :-)
If you would like to run Scala native in IntelliJ (I shifted to IntelliJ and still can't get my hands down) you need to make sure a few things are in order. Most of this happens under File -> Project Structure which requires you to create a project (when you get a hang of it, it is much more logical than Eclipse -- and Netbeans for that matter). I am also assuming you have selected a jdk, but this can also be done in the Project Structure.
Now, to Scala:
Make sure you have the Scala plugin. Visit the Settings (File -> Settings; can also be found at the start-up screen) and locate 'Plugins' (for me it's nr. 8 from the bottom). Under "Browse Repositories" you should be able to search for "scala", find and install a plugin.
1 A. If no plugins pops up you are probably using a version of intellij where scala is not (yet) supported. If that happens you can go to the homepage for the plugin and download the nightly build.
Import Scala as a library in File -> Project Structure -> Global Libraries. Click the plus sign, select Java (Scala is a Java-lib), browse to your scala-dir (which can be downloaded here: http://plugins.intellij.net/plugin/?id=1347) and select the lib directory. Press ok and you should see the library popping up on the list.
Make sure the facet (Scala framework) is in place. Goto File -> Project Structure -> Facets. Click on the plus-sign and find Scala. A sublink should appear (if not double-click the Scala link). Clicking the sublink make sure you have selected a compiler before continuing. This should be provided by the modules selected before. I normally use FSC (Fast Scala Compiler) but it's probably a good idea to test the basic settings before experimenting.
Make sure the Scala Module is in place. In Project Structure -> Modules click on the module you want to compile in scala and click the plus icon above and select Scala. Again be sure to select a compiler library.
If you want to, setup configurations for the compiler under the facet
Use sbt with sbt-idea plugin to generate idea project files for complex projects.
Or
For simple projects.
Add scala nature to the project, and you can right click and run any file extending App.
A good walk-through on how to set up a Scala project in Intellij is located here:
http://sonyarouje.com/2011/03/18/running-scala-in-intellij-idea-10/