How do I install scala-test with intellij. The video on the intellij website shows them adding a library dependency with scala-test showing up on the list. I don't have that however as I'll need to install scala-test somehow first. The quickstart on the scala website just seems to have a link to a jar file. Do I configure the IDE in some way to point to that jar file as a global library?
No need for a global library. Intellij IDEA supports adding libraries to your project directly from Maven. Here's how:
Go to File -> Project Structure
Select the Dependencies tab
Click the + sign at the bottom to create a new library
Choose "New Library" and seleect "From Maven" to add a new library from the public Maven repository
This brings up a search dialog which you can use to find the Maven dependency you want. Try searching for "org.scalatest:scalatest" to get the list of scalatest libraries.
To install the latest version of ScalaTest and its dependencies in IntelliJ IDEA 2016.3.2, you need:
Visit http://www.scalatest.org/install (section To include ScalaTest 3.0.1 in your Maven project) to fetch a list of reqiered libraries full names with the following structure {groupId}:{artifactId}:{version}, e.g.
org.scalactic:scalactic_2.11:3.0.1
org.scalatest:scalatest_2.11:3.0.1
Make sure that libraries names contain a Scala version you use in you project, i.e. above libraries are compatible with Scala 2.11 and not working with the new 2.12 version.
Go to File ⇒ Project Structure... or press Ctrl+Alt+Shift+S (Windows):
Go to Project Settings | Modules section and click on Dependencies tab. Then click + ⇒ 2 Library... ⇒ From Maven...:
Type in the full library name to install, then click Search button (or press Shift+Enter), select the library you need and click OK:
Repeat steps 3 and 4 until all dependencies are installed.
Related
IntelliJ-IDEA is new for me .. I used to work with SCALA-IDE. for current project i have to use IntelliJ.
I tried in stackoverflow to find "How to crate .jar file of scala maven project created in Intellij"
I found:
install SBT and on CMD type "sbt package"
install maven and on cnd type "maven package"
some says in intellij at right hand side there will be two options, one is maven, one is ant. Click on maven. U can see the modules. Click on the module un want to build. Expand module, expand the life cycle, click on install
My question is:
what is the best way to create .jar file in Intellij for maven project ). I have added all scala and spark the dependencies to pom.xml
FYI: I think the meaning of having a tool is usefully when you don't have to go to cmd and type "sbt package" or "maven package" . just a mouse click should work for you Like scala-IDE
You could use the Build Project from menu.
Build > Build Project
Or if you want more fine grain controls use the Maven Projects tab on the right to package.
I know there are Scala specific tools to create OSGi bundles, but I'm quite happy with bndtools, I just would like to write Scala alongside or instead of Java.
Assuming that bndtools and Scala IDE installed in eclipse (you find them the Eclipse Marketplace).
Create a new Bndtools OSGi project as you normally would (i.e. from the File menu, select New -> Bndtools OSGi Project)
Add the Scala nature to the project: Right click on the project in the Package Explorer view, and in the context menu select Configure → Add Scala Nature. (See http://scala-ide.org/docs/user/faq.html)
That's all for the eclipse side of things, you can now add Scala classes and everything will work the same way as it does with java.
To make sure things also work on the command line and on your CI Server some more steps are needed.
to the file build.gradle add the line:
apply plugin: 'scala'
to file gradle.properties add: scara.srcDirs=[projectDir/src]
UPDATE:
The above isn't quite enough, additional a build.bnd file has to be added to any submodule containing scala files. The following isn't elegant as it duplicates a dependency already in the bnd file, but so far the only solution I've found: https://github.com/fusepoolP3/p3-entry-resource/blob/0df0bc35311c8a361f95d8e72f91c5e0df929245/build.gradle
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/
I usually use .Net but now I'm playing Scala in IntelliJ 10.5.1. It's interesting how can I make a package which I can import to other projects?
If you want to create a jar file you do that through File->Project Structure->Artifacts hit the + sign choose Jar -> from module with dependencies
Then you can choose whether you want all the dependencies inside your jar or not
Then you can create the jar via the Build->Build Artifacts menu
When you have a new project you can reference that jar via the dependencies menu mentioned by Christian
I have a dependency on clj-record in my CounterClockwise project. What's the best way to manage this? Copy the source code or compile to a JAR and add it as a referenced library?
There are tools to help you:
http://github.com/technomancy/leiningen <- project based
http://github.com/liebke/cljr <- dependencies not project based
http://github.com/ninjudd/cake <- alternative build tool
Assuming your dependencies are available in a Maven repo (like central or clojars), you have a couple of options.
First, if you're using Leiningen, there is an eclipse plugin for it now that will manage project dependencies for you, based on the dependencies you define in your project.clj file. The plugin is in beta now, but has been working great for me so far. (Note that it uses Leiningen 2.0 under the covers, though that detail won't matter for many (most?) simple cases.)
If you're using Maven, the m2eclipse plugin makes it so that the dependencies you declare in your Maven pom.xml are automatically added to your eclipse project's build path, and are therefore available in CCW REPLs and such.
there seems to be no pattern for specifying dependencies apart from hacking the code into your project or building a jar externally.
Of course you can, just as with any java project. While dependency resolution isn't tied into eclipse (yet), once you retrieve the deps (via one of the command line tools nickik listed), you can specify which jars are to be included in the java build path of your eclipse project:
Retrieve the deps via cake, leiningen, etc.
Refresh the eclipse project so you see the deps (usually in the lib directory)
Highlight the jars you want eclipse to know about
Right-click, select Build Path > Add to Build Path
That's it. You can fiddle with the build path by going to the Java Build Path section of the project's properties window.