scala-cli
scala-cli copied to clipboard
I would like to be able to import libraries from Github Packages
Is your feature request related to a problem? Please describe.
My programming team publishes our libraries to Github Packages and I can't import them in a scala-cli
script. I would like to be able to.
I've seen documentation on how to make this work with GitHub "Releases". But Github Releases are different from Github Packages. Github Packages work like Maven repositories, and if you try to specify loading a library from Github Packages like you would specify it for GitHub Releases, you end up with a fatal error saying that the pom file for the library could not be located.
Describe the solution you'd like
Ideally, it would be nice to be able to specify Github Packages as a resolver. This is how it's done in sbt:
lazy val moreResolvers = Seq(
Resolver.githubPackages("myorg"),
)
// [...]
resolvers ++= moreResolvers
This solution requires an sbt plugin to work–it doesn't work out of the box. But with the plugin, it works great.
Describe alternatives you've considered
I could download the libraries I need and store them locally, but that would be a big pain in the butt. Especially since we have libraries that depend on quite a few other libraries. I don't want to be managing endless transitive dependencies by hand. I've done this in the past in other programming environments, and it was hell.
Workaround:
//> using repository "https://<username>:<personal_access_token>@maven.pkg.github.com/<owner>/<repo>"
(Do not share your personal access token though.)
I did not yet find a way to read the personal access token from e.g. ~/.m2/settings.xml
.
Amazingly, I think I actually got this to work, modulo some dependency hell issues with cats. (I'll have to try an experiment with simpler dependencies...)
The problem with this workaround is that I'd like to use this for production work, but I can't check in my personal access token into a GitHub repo.
It would probably work if I could grab the token somehow from the GITHUB_TOKEN environment variable, but I can't put in any code that would do so before using this using repository
directive, can I?
(Note: I didn't put the using
directive in a comment, but rather directly in the code. Which, fortunately, VSCode with Metals understands.)
A poor-man's solution to this problem might be just to provide a way to interpolate the contents of an environment variable into the string in a using
directive.
We're working on an easy of of setting up repository credentials it is tracked under #1629