scalameta / scalafmt

Code formatter for Scala
http://scalameta.org/scalafmt
Apache License 2.0
1.42k stars 276 forks source link

Scalafmt seems to ignore COURSIER_REPOSITORIES #3316

Closed PawanKartikS closed 1 year ago

PawanKartikS commented 1 year ago

Our environment does not support egress so we use Nexus repository manager. While we are able to use coursier to fetch what we want by specifying COURSIER_REPOSITORIES AND COURSIER_CREDENTIALS, scalafmt seems to hit oss.sonatype.org while resolving the version specified in the .scalafmt.conf file. If the former env variable isn't set, it straight away goes to maven. Am I correct in assuming that scalafmt supports COURSIER_REPOSITORIES, ref? If it does indeed support it, shouldn't it hit our Nexus instead?

Version: 3.5.9

Additional helpful information: I've tried running coursier to fetch something which hit our Nexus and was successful. The next immediate command that I ran was scalafmt as scalafmt Foo.scala --debug which hit some other endpoint/host instead of our Nexus. And because the egress is blocked, it simply sat there with the progress bar at 0%. I've double checked that the env variables are correct. Coursier being able to pull what I've asked for also shows that the configuration is correct.

Configuration

version = 3.5.9
...

Command-line parameters

scalafmt Main.scala --debug

Expectation

I'd expect that scalafmt format the code as per its functionality.

tanishiking commented 1 year ago

Hey, @PawanKartikS thank you for reporting! I tried to reproduce it with, for example

COURSIER_REPOSITORIES="jitpack" ./scalafmt --debug

but scalafmt correctly try to resolve from jitpack, and failed (because there's no binary on jitpack) then fallback to sonatype which is a default repository set by scalafmt. Which repository did you specify by COURSIER_REPOSITORIES?

PawanKartikS commented 1 year ago

I just specified 1 repository, our Nexus endpoint.

tanishiking commented 1 year ago

Can you download the scalafmt binary from the Nexus repository? scalafmt-cli does indeed support COURSIER_REPOSITORIES.

PawanKartikS commented 1 year ago

./cs bootstrap org.scalameta:scalafmt-cli_2.13:3.5.9 --verbose --standalone -o /some_path/scalafmt This command pulls 3.5.9 from Nexus. Is this what you're asking?

tanishiking commented 1 year ago

Hmm, then I have no idea what's going on in your environment 🤔

PawanKartikS commented 1 year ago

I have an update for you. I'm not sure how relevant it is but I thought I should point it out. When scalafmt is invoked, it very briefly, for a sec, hits our Nexus repo and then switches back to oss.sonatype.org. It happens so quickly that it was nearly impossible to notice. I had to record my screen and move frame by frame to notice this happen. Are there any scenarios where the scalafmt would switch the repo it is using without facing any error?

tanishiking commented 1 year ago

That happens if the binary is not found in the repository (that's why I asked "Can you download the scalafmt binary from the Nexus repository?") Can you find org.scalameta:scalafmt-core_2.13:3.5.9 from your nexus repository instead of scalafmt-cli (I guess you can though...)

PawanKartikS commented 1 year ago

Yes, I just pulled in org.scalameta:scalafmt-core_2.13:3.5.9 successfully and I can confirm that I was able to view it from within our repo manager. I even was able to pull a few other versions.