How to install Scala software - scala

I want to use a tool written by Scala but I have no experience with Scala.
The tool I want to use is from https://github.com/allenai/pdffigures2. It told me how to install the tool in the readme but I can not understand.
It said I need
resolvers += Resolver.bintrayRepo("allenai", "maven")
And then include
libraryDependencies += "org.allenai" %% "pdffigures2" % "0.0.11"
what does that mean, where should I add them? I am on Ubuntu. It would be kind if someone can tell me how to install this tool step by step, currently, there is not Scala in my computer.

Install sbt (Scala build tool) from here: http://www.scala-sbt.org/
Create a new Project with
sbt new scala/scala-seed.g8
cd <project_name>
vi build.sbt
Add your lines to this build.sbt. After that you can use the commands given in the section "Command Line Tools" of pdffigures2
Edit: Just saw that the library is only available for Scala 2.11. Could you change the scala version in build.sbt as follows:
scalaVersion := "2.11.11",

Related

SBT, Scala version mismatch

i have installed Scala 2.11.8 version, and i installed SBT 0.13.12 version as well.
when i create one directory and inside that directory typed sbt and sbt prompt opened. Inside SBT prompt, when i checked libraryDependencies i found like this:
sbt:sparkp> libraryDependencies
[info] * org.scala-lang:scala-library:2.12.4
But in machine, i have installed scala 2.11.8 version, when i checked scala -version it shows
hadoop#localhost:~$ scala -version
Scala code runner version 2.11.8 -- Copyright 2002-2016, LAMP/EPFL
Did i made any mistake while installing sbt? or i need to change any configuration properties after installation?
please help out.
Note: There are some questions regarding this error in stackoverflow, but i didn't get exact answer that's why i am asking new question.
In my opinion the scala version you are getting is the version with which sbt is built with.
The solution to your is to find global.sbt file which is usually in ~/.sbt/<version>/global.sbt
and add following line
scalaVersion := "2.11.8"
Your problem should be solved.
The Scala version of a project in SBT is completely unrelated to one you have installed and available from command line. This is a very good thing for several reasons:
Everyone who builds a project doesn't get different result depending on Scala version they have installed.
You don't need to install multiple Scala versions and switch between them all the time to work on multiple projects.
Many projects should be built with multiple Scala versions, see http://www.scala-sbt.org/0.13/docs/Cross-Build.html.
If you are creating a new project, you should specify scalaVersion := "2.11.8" (or any other you want) in build.sbt in this project.

What version manager should I use to manage multiple Scala versions?

I come from a background in Ruby, and I use RVM to manage multiple Ruby and gemsets. I have googled around, and I found these two SVM and PVM, not sure what should I use?
Anyone can recommend what should I use to manage multiple scala?
PVM Play Version Manager https://github.com/kaiinkinen/pvm
SVM Scala Version Manager https://github.com/yuroyoro/svm
You don't need a version manager. You need a build tool.
Scala projects work differently than Ruby projects. If you use SBT as a build tool, you specify the Scala version in your build file:
//build.sbt
scalaVersion := "2.11.0" // or some other version
SBT then proceeds to download the specified Scala version for you if it hasn't been downloaded before, and builds and runs your project with this version. If you want, you can even specify which version of SBT you want, and it'll arrange everything for you as well.
This is because Scala, contrary to Ruby, is a compiled language - it must be compiled/built before running. Ruby projects don't have a build process, and can be (attempted to) run on any Ruby version. Scala projects might not build on incompatible versions, let alone run, so you need to specify which Scala version your project is supposed to be built against.
There's also no such thing as gemsets for Scala. For Ruby, gems were originally system-wide libraries and executables, shared by all Ruby scripts on the system. Therefore, gems override each other and you need to maintain gemsets with the specific versions you require for each project. In Scala, a dependency is just a library specifically for your project. They don't override each other, and you just specify which version you need in your build file. SBT then automatically downloads it for you when you build.
This just works:
// myproject1/build.sbt
scalaVersion := "2.10.2"
libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.2.0"
// myproject2/build.sbt
scalaVersion := "2.11.0"
libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.3.3"

How do I tell sbt to use local scala installation?

Trying to learn how to use sbt and stuck with a situation: when I install sbt and run it for the first time, it tries to download scala 2.9.x into some directory inside my home. I have scala 2.10.2 installed somewhere else, so how do I tell sbt to use that scala distribution?
UPD.: Solution (this is distribution for sbt to use when building projects, but sbt will anyway download scala distribution needed for it itself):
***#***:~|⇒ cat .sbt/global.sbt
scalaVersion := "2.10.2"
scalaHome := Some(file("/usr/share/scala"))
You could copy the .jars of your distribution to ~/.ivy2/cache. But that would be totaly missing the point of using sbt. If you want to use scala 2.10.2, just put
scalaVersion := "2.10.2"
into your build.sbt, and it will download this version for you. Then if you want to update to 2.11 when it comes out, all you have to do is change a single line in your build.sbt.

sbt version and scala version. project configuration for intellij idea with sbt-idea plugin

I follow these steps to configure a project for IntelliJ idea.
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.2.0")
I use sbt-idea for sbt version 0.12 with fixed bug for Idea.
When I type sbt in my project's directory, I noticed that it uses scala 2.9.2.. but I'm going to use scala 2.10.1 for my project.
Questions:
Does it make sense which scala version to use for plugin(s) (~/.sbt/plugins)-compilation, or I should use one/same scala version for everything? Can I change scala version for plugins?
So, I created ~/.sbt/plugin/build.sbt file with mentioned content.
that version is out of date, it depends on sbt-idea 1.2.0-SNAPSHOT. The latest at the time of writing is 1.3.0
See my project skeleton for an implementation using the latest versions of scala, scalatest and SBT to IDE project plugins.
Actually I got it.
if you have a project with build.sbt (that uses 2.10.1 scala) file - as soon as you type sbt.. all dependencies will be downloaded into ~/.sbt folder - even scala compiler will be downloaded there (~/.sbt/boot). It could be even several version of scala: 2.10.1 and 2.9.2 for example.
and about sbt-idea and ~/sbt/plugins .. it could any scala version - depending on its build.sbt file, for example in my case:
resolvers += "Sonatype snapshots" at
"http://oss.sonatype.org/content/repositories/snapshots/"
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.2.0-SNAPSHOT")
I should notice if try different version.. like 1.1.0-M2-TYPESAFE it will not work.. (at least in my case) - gen-idea command is not available then. I do not know why. I guess it should.
Also if you do not point resolvers += - it will will not work.. but it it will not tell you about that..
This plugin is using scala 2.9.2 - we can not see it here, but we can see it from that outputs it produces while installing/downloading. That's why we have ~/.sbt/boot/scala-2.9.2/ as a result.
In any case we should not care about it. It is handled by sbt.
When you converted your sbt-project into your intellij-idea project by typing gen-idea in sbt console, as the result your IDE project will be referencing to ~/.sbt/scala but not to your somewhere-installed-scala.. So even no need to pointing the scala location - that sbt-idea sbt's plugin will do all the work. And that's good!
That's the answer I wanted to get. One gets/understands it by trying it.

How to get sbteclipse working with Scala 2.9

I am playing with the spray template project and Scala 2.9.0.1.
I want to work with Eclipse and so I've added the following lines to the build.sbt file
of the spray template project.
resolvers += {
val typesafeRepoUrl = new java.net.URL("http://repo.typesafe.com/typesafe/releases")
val pattern = Patterns(false, " [organisation]/[module]/[sbtversion]/[revision]/[type]s/[module](-[classifier])-[revision]. [ext]")
Resolver.url("Typesafe Repository", typesafeRepoUrl)(pattern)
}
libraryDependencies <<= (libraryDependencies, sbtVersion) { (deps, version) =>
deps :+ ("com.typesafe.sbteclipse" %% "sbteclipse" % "1.3-RC2" extra("sbtversion" -> version))
}
I always get this error:
com.typesafe.sbteclipse#sbteclipse_2.9.0-1;1.3-RC2: not found
Of course the directory at the typesafe server does not exist. There is only:
http://repo.typesafe.com/typesafe/releases/com.typesafe.sbteclipse/sbteclipse_2.8.1/
but sbt is trying to get:
http://repo.typesafe.com/typesafe/releases/com.typesafe.sbteclipse/sbteclipse_2.9.0-1/0.10.1/1.3-RC2/jars/sbteclipse_2.9.0-1-1.3-RC2.jar
I figured out that 2.8.1 is the scala version sbt uses internaly. But my
sbt version (0.10) uses the scala version set in the build.sbt (scalaVersion := "2.9.0-1") to build the url to download sbteclipse.
Does anyone know how to set this up correctly? How do I tell the build.sbt file that I want to use Scala 2.9 but to look for the sbteclipse plugin at the correct URL?
Are there any plans to include something like sbteclipse to the sbt standard distribution? That would be more than welcome and probably help a lot of beginners with Scala, sbt and Eclipse.
Claus
try some thing like "com.typesafe.sbteclipse" % "sbteclipse_2.8.1" % "1.3-RC2....."
using "%%" will automicly add scala version to the library name. using "%" will not.
There is also a shorter way to get sbteclipse into use. Create a file ~/.sbt/plugins/plugins.sbt with this content:
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.0")