I need to install the scala interpreter (aka repl). The official website https://scala-lang.org/download/ gives me instructions on how to install sbt. I have installed sbt, but still do not have the interpreter. What am I missing here? I am supposed to type scala followed by the Enter key.
[Edit] Someone suggested me to type "console" after sbt is running, but I got an error message
sbt:slides> console
[info] Compiling 1 Scala source to /Users/zell/slides/target/scala-2.12/classes ...
[error] /Users/zell/slides/examFakeSolution.scala:108:10: not found: value fpinscala
[error] import fpinscala.monoids.Monoid
[error] ^
[error] /Users/zell/slides/examFakeSolution.scala:128:45: not found: type Monoid
[error] def foldBack[A] (l :List[A]) (implicit M :Monoid[A]) :A =
[error]
....
If you have sbt, you have the REPL. You are doing it right, you can run sbt and then console or directly run sbt console
The error is a compilation error. Fix it first and then you'll be able to run the REPL in that folder.
When you run the REPL, sbt tries to compile the project first. So you can also run it in any folder other than the one from the project and it will work fine.
If you want start scala REPL inside SBT, type sbt firstly, then console
To start REPL without installing SBT, download the Scala from official site, add %SCALA_HOME%/bin to PATH and type scala in the terminal.
Related
I tried running my Scala code in VSCode editor. I am able to run my script via spark-submit command. But when I am trying with scalac to compile, I am getting:
.\src\main\scala\sample.scala:1: error: object apache is not a member of package org
import org.apache.spark.sql.{SQLContext,SparkSession}
I have already added respective library dependencies to build.sbt.
Have you tried running sbt compile?
Running scalac directly means you're compiling only one file, without the benefits of sbt and especially the dependencies that you have added in your build.sbt file.
In a sbt project, there's no reason to use scalac directly. This defeats the purpose of sbt.
I have a piece of code where I am explicitly passing a type parameter which is picked up just fine by intelliJ and there is no error pointed out by intelliJ, but when I use system sbt to compile the same code it doesn't pick up the type parameter and get confused with multiple matching implicit types in the scope.
Code in intelliJ with no error flagged :
Error stack when compiled on system sbt :
[error] one error found
[error] /Users/xxxxxx/projects/xxxxx-xxxxxx-xxxxxx/xxxxxxxxx/src/main/scala/com/xxxxxxx/Main.scala:93:33: ambiguous implicit values:
[error] both lazy value AsyncBlobIO in trait Instances of type => cats.effect.Async[doobie.free.BlobIO]
[error] and lazy value AsyncCallableStatementIO in trait Instances of type => cats.effect.Async[doobie.free.CallableStatementIO]
[error] match expected type cats.effect.Sync[F]
[error] result <- jobPaths(Paths.get(record.path), settings.baseFolder).use(paths => ingestionJob(record, paths))
[error] ^
As you can see the system sbt doesn't pick type argument jobPaths[IO](..) instead just runs jobPaths(..) for some reason.
JobPaths functions definition if that helps :
def runJob[F[_]](
settings: Settings,
now: Instant,
consulSessionName: String,
assignerConfig: PartitionKeyAssignerConfig
)(implicit F: ConcurrentEffect[F], p: Parallel[F]): F[Unit] = {
system sbt version :
[info] 1.2.8
sbt script version: 1.3.12
Am I looking at the problem the right way? or this is caused by something else?
Anything would be helpful.
System sbt which uses Scala compiler proper is authoritative over IntelliJ Scala compiler. When the two disagree you should go with former. Make sure to enable use sbt shell to minimise discrepancies. Note that even with use sbt shell enabled the in-editor error highlighting might give false positives because it uses a separate process from Scala proper. An alternative to consider is Metals which should not have such discrepancies.
When I try to create the ScalaTest example with this command:
sbt new scala/scalatest-example.g8 fails on TransportException
I get the following:
[info] Set current project to scala (in build file:/Users/chasrmartin/Dropbox/Etudes/Scala/)
[error] org.eclipse.jgit.api.errors.TransportException: git#github.com:scala/scalatest-example.g8.git: Auth fail
[error] at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:139)
[error] at org.eclipse.jgit.api.CloneCommand.fetch(CloneCommand.java:193)
I've tried several workarounds from around the next (eg this SO question) to no avail. It would seem this has to be a simple problem, I got this command from a beginners tutorial.
Update
I got this command from https://www.scala-lang.org/documentation/getting-started-sbt-track/testing-scala-with-sbt-on-the-command-line.html
This project doesn't seems to exists anymore.
Instead I would prefer to run with the normal scala-seed.g8
> sbt new scala/scala-seed.g8
And add the test classes manually.
This is an equivalent tutorial with the same classes and tests.
The scala seed template already comes with the structure you want, with the test dependency. You can run sbt test normally.
I am building spark project with SBT (scala version 2.10.4):
sbt -Pyarn -Phadoop-2.4 -Dhadoop.version=2.4.0 -Phive
-Phive-thriftserver -DskipTests clean package
Then I obtain the following error:
[error]
/home/gracer/Desktop/test/mllib/src/main/scala/org/apache/spark/ml/recommendation/contextaware/CAMFCU.scala:1514:
withFilter' method does not yet exist on
org.apache.spark.rdd.RDD[(Int,
scala.collection.mutable.Map[Long,Float])], usingfilter' method
instead [error] for ((bid, errors) <- errorsTerms) {
The strange thing is that I was previously able to compile and execute the project, but for some reason it now gives an error.
I cloned the project from:
https://github.com/dpp/simply_lift.git
Then I followed the instructions which state:
Change directories into the chat directory and type sbt update ~jetty-run.
SBT fetches dependencies, and then I get this:
[error] Not a valid command: jetty-run
[error] Expected '/'
[error] Expected ':'
[error] Not a valid key: jetty-run (similar: run)
[error] jetty-run
[error]
Now what?
In versions of SBT newer than 0.10.0, ~jetty-run has been removed in favour of:
container:start
container:stop
deployment // compiles the changes made while jetty is running.
You should've used sbt from the packaged archive (./sbt). Instead of a system-wide SBT (which may be new).
Anyway, I suggest to use use the new SBT and everything new, too. This is the official and good starting point for a project: https://github.com/lift/lift_25_sbt/
(personally I use it and I'm cool with how it works)