Trying to compile the FP in Scala project from GitHub

I try to compile the FP in Scala project from GitHub:

I have installed scala-cli via coursier and then I have clone https://github.com/fpinscala/fpinscala.git

Now in the fpinscala directory I issue:

$ scala-cli compile .

After 45sec of downloading I get:

[hint] ./fpinscala/build.scala:8:15
[hint] "munit is outdated, update to 1.0.0"
[hint]      munit 0.7.29 -> org.scalameta::munit:1.0.0
[hint] //> using lib org.scalameta::munit:0.7.29
[hint]               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
[hint] ./scala-cli/basic/parseMeFast.scala:1:15
[hint] "fastparse is outdated, update to 3.1.1"
[hint]      fastparse 3.1.0 -> com.lihaoyi::fastparse::3.1.1
[hint] //> using dep com.lihaoyi::fastparse::3.1.0
[hint]               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Why’s that? A version issue? Any idea how to fix this?

That will still compile fine.
If you want, you can make the suggested changes manually in the build.scala file.

I’m guessing it’s because SBT and Scala-cli are somewhat different in their purpose.
SBT is more focused on “freezing” dependency versions.
Scala-cli will always tell you to update to the latest (unless you turn that off somehow).
FPinscala was made primarily as an SBT project, they must have added the Scala-cli option later.

Sorry to say, but it does not. I left out the final line:

Compilation failed

Update:

When I run the compile commad again I now get:

[warn] ./build.scala:8:11
[warn] Using 'lib' is deprecated, use 'dep' instead
[warn] //> using lib org.scalameta::munit:0.7.29
[warn]           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Compiling project (Scala 3.3.0, JVM (22))
Error: 22 is not a valid choice for -java-output-version
  scalac -help  gives more information
Error compiling project (Scala 3.3.0, JVM (22))
[hint] ./build.scala:8:15
[hint] "munit is outdated, update to 1.0.0"
[hint]      munit 0.7.29 -> org.scalameta::munit:1.0.0
[hint] //> using lib org.scalameta::munit:0.7.29
[hint]               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Compilation failed

Maybe the line

Error: 22 is not a valid choice for -java-output-version

was there before, but I missed it inmidst all the Downloading lines.

New question:

How can i find out what a “valid choice” for the JVM is?

Scala-cli is not yet supported on Java 22.
(I think the Scala compiler itself does not support Java 22 yet.)
Java 21 and below are fine.

Here’s what I got

╰─ scala-cli compile .                                                                            ─╯
[warn] ./build.scala:8:11
[warn] Using 'lib' is deprecated, use 'dep' instead
[warn] //> using lib org.scalameta::munit:0.7.29
[warn]           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Starting compilation server
Compiling project (Scala 3.3.0, JVM (17))
Compiled project (Scala 3.3.0, JVM (17))
[hint] ./build.scala:8:15
[hint] "munit is outdated, update to 1.0.0"
[hint]      munit 0.7.29 -> org.scalameta::munit:1.0.0
[hint] //> using lib org.scalameta::munit:0.7.29
[hint]               ^^^^^^^^^^^^^^^^^^^^^^^^^^^

It’s obvious that FpinScala guys are not following up on changes to Scala-cli and libraries. Scala-cli is still new and fast-changing.

If you want to get rid of all the warnings, change the last line to

//> using dep org.scalameta::munit:1.0.0

Java 22 is supported since Scala 3.4.0 and would be supported by upcoming Scala 3.3.4.
Newer Scala version can be passed on the command line using -S <version>, scala-cli compile . -S 3.3.3. For the purpose of learning from this project I’d suggest to stick with Scala 3.3 (LTS) line to that it would the most match the outputs expected by the book author.

1 Like

Ah, so it’s because of Scala 3.3.0 in the project. Got it!

I got it all working with

scala-cli compile --jvm 19 .

Thanks for pointing me in the right direction. :smile:

1 Like

Feel free to open a PR on the fpinscala/fpinscala repository and I’ll happily merge. Thanks!

1 Like

Done!