Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to set the Scala version or the Ammonite version #1093

Open
julienrf opened this issue Jun 7, 2020 · 8 comments
Open

Unable to set the Scala version or the Ammonite version #1093

julienrf opened this issue Jun 7, 2020 · 8 comments

Comments

@julienrf
Copy link

julienrf commented Jun 7, 2020

The fact that Scala and Ammonite evolve can make it impossible to run old scripts with a new version of Ammonite.

This problem is solved by sbt by having a build.properties file that sets the sbt version, and then a scalaVersion setting that sets the Scala version. This allows me to keep untouched very old programs and still be able to run them with the latest sbt launcher.

I would like to see a similar mechanism here. Maybe with magical imports?

import $amm.`2.1.4`
@alexarchambault
Copy link
Collaborator

ammonite-runner allows things along the lines of what you're proposing, by acccepting Ammonite and / or Scala versions in comments before any scala code, like

// Ammonite 2.1.4, scala 2.12.11

For now, it can be run scripts with

$ cs launch io.github.alexarchambault.ammonite::ammonite-runner-cli:0.2+ -- script.sc

(Note that this will works when its 0.2.5 version its Maven Central, because of some recent regressions…)

It's initially been written to fetch Ammonite from metals. I'd be ok moving it to the main repo if it makes sense for everyone. And / or tweak the way it reads the Ammonite and scala version from scripts.

@alexarchambault
Copy link
Collaborator

In the mean time, coursier allows to run specific Ammonite / scala combinations, like

$ cs launch ammonite:2.0.4 --scala 2.12.8

or

$ cs launch ammonite --scala 2.13

(Both full and binary version are accepted as scala versions, and the Ammonite version is optional.)

@SethTisue
Copy link

I'm glad there's a ticket on this because it's actually one of the things that has held me back from adopting Ammonite for my own scripting. (And yes, I should have opened an issue myself, long ago.)

I'll try to find time to give ammonite-runner a spin, looks cool

@shivam-880
Copy link

shivam-880 commented Jun 21, 2021

One can use the workaround above in bash script like so:

cs launch ammonite --scala 2.12.10 -- myscript.sc args

@julienrf
Copy link
Author

I think it would be better to find a solution that does not require a custom way of running the application. Basically, if I distribute an ammonite script, I want users to be able to run it by just running amm the-script.sc, I don’t want to have to also distribute a script that runs the script.

@ptrdom
Copy link

ptrdom commented Apr 19, 2022

Are there any plans to implement this feature? Or an idea on how to go about it? I would think that it is quite critical for the proper use in production environment, I could work on it.

@julienrf
Copy link
Author

Hello @ptrdom, would using scala-cli instead of ammonite work for you? Scala-cli does support this feature.

@ptrdom
Copy link

ptrdom commented Apr 19, 2022

Hey @julienrf, I had not heard about scala-cli before and after a quick glance it does seem to have the features I need, many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants