Ammonite
Ammonite copied to clipboard
@main does not work on scala 3.0.0 (homebrew installation)
homebrew is installing scala 3.0.0
% amm
Loading...
Welcome to the Ammonite Repl 2.4.0 (Scala 3.0.0 Java 16.0.1)
@
%amm rip7.sc --i 5 --s 'abc'
hello 2
Script rip7.sc does not take arguments: "--i" "5" "--s" "abc"
and the script is:
% more rip7.sc
val x = 1
@main
def main(i: Int, s: String, path: os.Path = os.pwd) = {
println("hello");
s"Hello! ${s * i} ${path.last}."
}
println("hello 2");
however, this script works when I download ammonite directly (it uses scala 2.13)
% ~/amm
Loading...
Welcome to the Ammonite Repl 2.4.0 (Scala 2.13.6 Java 17)
@
% ~/amm rip7.sc -i 5 -s 'abc'
hello 2
hello
"Hello! abcabcabcabcabc tmp."
I can confirm this: it works with Ammonite 2.4.0 and Scala 2.13, but not with the combination 2.4.0 and Scala 3.0.
$ amm3 re1.sc all
Script re1.sc does not take arguments: "all"
This is independent of homebrew. I generated the amm3 above with
sudo sh -c '(echo "#!/usr/bin/env sh" && curl -L https://github.com/com-lihaoyi/Ammonite/releases/download/2.4.0/3.0-2.4.0) > /usr/local/bin/amm3 && chmod +x /usr/local/bin/amm3' && amm3
I've encountered this bug as well.
For an identical script, it works correctly on Ammonite w/2.13, but does not pick up the @main
function on Ammonite w/3.
Tested on Ammonite 2.4.0 with AdoptOpenJDK 11.0.11
I've opened a discussion on Homebrew to ask if the version there can be reverted to the stable 2.13-2.4.0
version: https://github.com/Homebrew/discussions/discussions/2117
@lihaoyi Is there any way to get arguments in ammonite script with scala 3.x?
This might be related to #1150.
See also: https://contributors.scala-lang.org/t/plan-for-main-and-mainargs-in-scala3/4897
this may fix it: https://github.com/com-lihaoyi/Ammonite/pull/1298