How to make an import available on scala-cli repl start up

I have a Scala CLI project with all its code under the project root. the projects defines the package org.mydomain.mygroup.myproj.

After I drop into a REPL from the project root via

scala-cli repl . -O -explain

I can do

import org.mydomain.mygroup.myproj._

and all definitions of the project are available. So far so good.

Now I try to put this import statement into the scala-cli command line:

scala-cli repl . -O -explain -e "import org.mydomain.mygroup.myproj._"

This executes without complain, but the definitions of my project are not available in the REPL.

What goes wrong? How can I write the command that the definitions are available?


ps: I also tried to put the import into a init.scala file and call it like this

scala-cli repl . -O -explain init.scala

However I get the same result: No complaint, but no definitions available either.

This is a requested feature:

4 Likes

It is on the roadmap:

1 Like

Wonderful! Thank you.

1 Like

Back in Scala 2, you could start the REPL with a -i command line option to automatically import something. I put that in a two-line bash script to use the REPL as a units-aware calculator based on my scalar class for physical units. For some unexplained reason, however, the -i option got lost in Scala 3.

I don’t think you would find the explained reason very satisfying.

It couldn’t be any less satisfying than not knowing why.

I found a workaround using sbt, but it requires access to sbt, whereas the -i option does not.