scalacenter / scalafix

Refactoring and linting tool for Scala
https://scalacenter.github.io/scalafix/
BSD 3-Clause "New" or "Revised" License
831 stars 186 forks source link

sbt-scalafix "Credentials file **** does not exist" #2007

Closed cptwunderlich closed 4 months ago

cptwunderlich commented 5 months ago

One month ago, scala-steward upgraded the sbt-scalafix plugin to v 0.12.1 and the build of this branch has been broken since, now I'm investigating.

Strangely, the build only fails in CI, but works locally. We have used sbt-scalafix 0.12.0 before and it worked fine, no other changes. We use a custom resolver to a private Sonatype repo, i.e., in plugins.sbt we have resolvers += "Sonatype Something" at "https://something".

Credential files exist in ~/.config/coursier/credentials.properties and ~/.sbt/credentials.

Stacktrace:

[warn] Credentials file **** does not exist
[warn] Credentials file **** does not exist
[warn] Credentials file **** does not exist
[warn] Credentials file **** does not exist
[error] java.lang.RuntimeException: Credentials file **** does not exist
[error]     at scala.sys.package$.error(package.scala:30)
[error]     at sbt.librarymanagement.ivy.Credentials$.toDirect(Credentials.scala:36)
[error]     at sbt.librarymanagement.ivy.Credentials$.$anonfun$allDirect$1(Credentials.scala:31)
[error]     at scala.collection.immutable.List.map(List.scala:293)
[error]     at sbt.librarymanagement.ivy.Credentials$.allDirect(Credentials.scala:31)
[error]     at scalafix.sbt.ScalafixPlugin$.$anonfun$buildSettings$1(ScalafixPlugin.scala:297)
[error]     at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error]     at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:63)
[error]     at sbt.std.Transform$$anon$4.work(Transform.scala:69)
[error]     at sbt.Execute.$anonfun$submit$2(Execute.scala:283)
[error]     at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:24)
[error]     at sbt.Execute.work(Execute.scala:292)
[error]     at sbt.Execute.$anonfun$submit$1(Execute.scala:283)
[error]     at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error]     at sbt.CompletionService$$anon$2.call(CompletionService.scala:65)
[error]     at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]     at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
[error]     at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error]     at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
[error]     at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
[error]     at java.base/java.lang.Thread.run(Thread.java:840)
[error] (ThisBuild / scalafixSbtResolversAsCoursierRepositories) Credentials file **** does not exist

I've seen these initial warnings before, but everything works normally after that. This exception is new. As I said, nothing else changed, only the sbt-scalafix version.

The stack-trace leads to ScalafixPlugin.sbt:297 and I can see that this code was added in the latest release, with PR 404.

Do you have any pointers on what changed here and what credential files scalafix is looking for now?

Sbt version used is 1.9.9

EDIT: We're only using the OrganizeImports task, no custom tasks. So the private repo is only for our build artifacts. Scalafix is run in our formatting step, which runs scalafmt and scalafix. So I'm not sure why it would even need any credentials...

bjaglin commented 4 months ago

Thanks for the report @cptwunderlich !

I've seen these initial warnings before, but everything works normally after that.

You probably have an invalid setup around credentials on CI, which sbt handles gracefully, but sbt-scalafix does not. I'll open a PR to align the behavior.

bjaglin commented 4 months ago

This should be fixed in the latest snapshot being published right now

addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.12.1+6-861ec563-SNAPSHOT")
resolvers += Resolver.sonatypeRepo("snapshots")