Downgrade Scala from 2.12 to 2.11.x - scala

I am learning Scala and downloaded IntelliJ Idea. I installed the Scala plugin and was instantly given the 2.12 version. Now I am trying to downgrade to 2.11 because I need this version to follow along a Coursera class I am taking.
I am having the same "UNRESOLVED DEPENDENCIES" shown in the link below:
SBT project refresh failed [IntelliJ, Scala, SBT]
I tried to solve my problem by doing what #Haspemulator suggested, but I'm still getting error messages. Here is a screenshot of what I have now:
(Notice that there is a folder called scala-2.12)

The error you get states that "Cannot add dependency ... to configuration "Test" because this configuration doesn't exist!" There's no such predefined configuration as "Test". There's only "test" (lower case). Try to use it instead.

CatherineAlv has already solved the problem. I am just segregating the steps together.
I too faced this problem while setting up scala for coursera course "Functional Programming Principles in Scala". By default build.sbt was showing scalaVersion as 2.12.x but I needed 2.11.x for the course. This can be easily solved in two steps:
Change the scalaVersion in build.sbt. The code would look like after change:
name := "Example"
version := "1.0"
scalaVersion := "2.11.8"
Build it.
Add the libraryDependencies to build.sbt. The code would now look like this:
name := "Example"
version := "1.0"
scalaVersion := "2.11.8"
libraryDependencies += "org.scalatest" %% "scalatest" % "2.2.6" % "test"
Build again.
This should solve it.

Related

How to make IntelliJ scala project use Scala 2.9.2 version?

I'm trying to create jar file from scala file - which will be used for Scalatron bot (http://scalatron.github.io/)
The problem is that if I create jar file using new scala versions 2.10 - 2.13 (these are the only one's that InteliJJ allows me to use) scalatron bot doesn't work.
However I found out that downgrading to scala 2.9.2 fixes the problem (Getting Scalatron to Work (trouble with opcode)).
How to downgrade to 2.9.2 on Intellij?
SBT is fully integrated with IntelliJ Idea, so you can create a SBT project in IntlliJ and make up the build.sbt file by yourself and put in it the scala version you want, compile, package and execute with SBT
name := "scalatron"
version := "0.1"
scalaVersion := "2.9.2"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.0-SNAP3" % Test

Using IntelliJ, how to add dependency in an sbt project

I'm new to sbt and I wanted to learn it with a small Scala project in IntelliJ.
I started with the official sbt Getting Started guide, to learn the sbt basics on the console (https://www.scala-sbt.org/1.x/docs/sbt-by-example.html). Following the guide, everything compiles fine.
Then I created an sbt project in IntelliJ, trying to do the same thing there. When I add the org.scalatest depenpency to the build.sbt file the project can no longer compile. The error message is:
module not found: org.scalatest#scalatest_2.13;3.0.5
When I created the fresh sbt project in IntelliJ, first the build.sbt looked something like this:
name := "sbtTest"
version := "1.0"
scalaVersion := "2.13.0"
Then I added the dependency:
name := "sbtTest"
version := "1.0"
scalaVersion := "2.13.0"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % Test
After reloading the build file and getting the error when compiling, I tried to change the biuld.sbt according to the code which already worked in the sbt Getting Started guide:
ThisBuild / scalaVersion := "2.13.0"
ThisBuild / organization := "me"
ThisBuild / version := "1.0"
lazy val sbtTest = (project in file("."))
.settings(
name := "sbtTest",
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % Test
)
This has again the same error after reloading and compiling.
My sbt version is 1.2.8.
Is something wrong with my build.sbt? Or is the sbt version too new for IntelliJ? Is IntelliJ probably not the recommended IDE to create Sala sbt projects?
Structure of both your build.sbt is ok. The thing seems to be in versions.
Scalatest 3.0.5 is currently unavailable for Scala 2.13.0. It's available for Scala 2.13.0-M2.
It's Scalatest 3.0.8 that is available for Scala 2.13.0.
https://mvnrepository.com/artifact/org.scalatest/scalatest
After you fix versions in build.sbt re-import IntelliJ project in pop-up window
or in sbt tool window
or in sbt shell

Spark-Scala build.sbt libraryDependencies UnresolvedDependency

i'm trying to import a dependency in my build.sbt file from here
https://github.com/dmarcous/spark-betweenness.
When i hover on the error it says:
Expression type ModuleID must confirm to Def.SettingsDefinition in SBT file
Unresolved Dependency
I am new in scala so my question may be silly.Thanks in advance
It is still unclear how your build configuration looks like, but the following build.sbt works (in the sense that it compiles and does not show the error that you mentioned):
name := "test-sbt"
organization := "whatever"
version := "1.0.0"
scalaVersion := "2.10.7"
libraryDependencies += "com.centrality" %% "spark-betweenness" % "1.0.0"
Alternatively, if you have a multi-project build, it could look like this:
lazy val root = project
.settings(
name := "test-sbt",
organization := "whatever",
version := "1.0.0",
scalaVersion := "2.10.7",
libraryDependencies += "com.centrality" %% "spark-betweenness" % "1.0.0"
)
However, you're probably going to find that it still does not work because it cannot resolve this dependency. Indeed, this library does not seem to be available neither in Maven Central nor in jcenter. It is also very old - it appears to only be published for Scala 2.10 and a very old Spark version (1.5), so most likely you won't be able to use it with recent Spark environments (2.x and Scala 2.11).

Scala error when running test in new application. can't expand macros?

I am trying to learn the basics of Scala, scalatest, and sbt and I'm following a tutorial. This is my built.sbt file:
name := "demo-hello"
version := "0.1"
scalaVersion := "2.12.6"
libraryDependencies += "org.scalatest" % "scalatest_2.10" % "2.1.0" % "test"
I have a test that looks like this (showing this is probably unnecessary:
package demo
import org.scalatest.FunSuite
class HelloTest extends FunSuite {
test("say hello method works correctly") {
val hello = new Hello
assert(hello.sayHello("Scala") == "Hello, Scala!")
}
}
What should I do from here? I am trying to run the test but I get this error:
Error:(8, 36) can't expand macros compiled by previous versions of Scala
assert(hello.sayHello("Scala") == "Hello, Scala!")
I'm not that familiar with the % symbol btw.
FIX
I changed my build.sbt to this:
name := "demo-hello"
version := "0.1"
scalaVersion := "2.10"
libraryDependencies += "org.scalatest" % "scalatest_2.10" % "2.1.0" % "test"
Remaining questions:
So it seems downgrading to scalaVersion "2.10" worked. Why?
What is an artifact? scalatest is apparently an artifact?
Where is scalaversion 2.10 kept on my machine? It seems I only have scala 2.12. Where in my project folder is version 2.10?
Answering your questions slightly out-of-order:
2 - An "artifact" is something that's built by maven, sbt, or another build system. For Scala or Java, this is almost always a jar file. Each item in libraryDependencies specifies a file in a maven repository (a database of artifacts).
1 - Scala class files are not compatible between minor versions of Scala. When you download a Scala jar from a maven repository, the Scala version is specified as part of the artifact name. The _2.10 in your dependency declares that you wish to use the version of scalatest that's compile for Scala 2.10 - which is why you were getting an error using it in your Scala 2.12 application.
When declaring dependencies on Scala artifacts in sbt, you should always use the %% operator, which automatically appends the appropriate suffix to your artifact, like so:
// This works for any scalaVersion setting.
libraryDependencies += "org.scalatest" %% "scalatest" % "2.1.0" % "test"
3 - sbt handles downloading the appropriate runtime files for the declared version of Scala automatically.

how to configure 2.9.1 in org.scala-sbt#sbt_2.9.1;0.12.3

I am trying a very simple sbt example; when I compile it with sbt, and always get the following error:
org.scala-sbt#sbt_2.9.1;0.12.3: not found
I found a build.properties file under project folder, where I could change the 0.12.3 part; for example, after I changed it to 0.11.3, it will succeed until another inompatible issue; However, I want to know how to change sbt_2.9.1 to, say, sbt_2.9.2; I don't find a configuration file, and even I update the sbt to the latest version 0.12.3, still no luck.
my build.sbt file:
organization := "com.typesafe.slick"
name := "slick-examples"
version := "1.0.1-RC1"
scalaVersion := "2.10.1"
scalacOptions += "-deprecation"
anyone please help me.
The Scala version sbt is using internally and the one used for your project are totally independent. Which sbt launcher are you using? Make sure you are using an sbt.version property that works for your sbt launcher.
Again, no need to configure the Scala version for your project at that level. Write a build.sbt file and set scalaVersion to, e.g. 2.10.1 (assuming you use sbt 0.12.x): scalaVersion := 2.10.1