rtimush / sbt-updates

sbt plugin that can check Maven and Ivy repositories for dependency updates
BSD 3-Clause "New" or "Revised" License
761 stars 55 forks source link

Updates are not found when credentials file is configured, but not present. #123

Closed mhogerheijde closed 5 years ago

mhogerheijde commented 5 years ago

Our internal nexus repository needs credentials to publish artefacts, but none to download them.

We do this by having a sbtCredentials.ini on our build server and our build.sbt contains

ThisBuild / credentials += Credentials(Path("/var") / "jenkins_home" / "sbtCredentials.ini")

This file is not present on our development machines.

When running sbt dependencyUpdates on our local machines, it reports "no updates found". When I remove the line, it does find updates.

build.sbt (cut down to the bare minimum to show the issue):

ThisBuild / name           := "Test Dependencies"
ThisBuild / normalizedName := "dependencies"
ThisBuild / description    := "Show that dependencyUpdates doesn't work with missing credentials file"
ThisBuild / organization   := "org.example"
ThisBuild / version        := "0.1.0"
ThisBuild / scalaVersion   := "2.12.8" // version 2.12.10 is available

ThisBuild / credentials += Credentials(Path("/var") / "jenkins_home" / "sbtCredentials.ini")

lazy val dependencies = project
  .in(file("dependencies"))
  .settings(
    libraryDependencies ++= Seq(
      "com.github.ghik" %% "silencer-lib" % "1.3.1", // version 1.4.2 is available
    ),
  )

project/plugins.sbt:

addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.4.2")

When I run sbt dependencyUpdates:

➜ sbt dependencyUpdates
[info] Loading settings for project global-plugins from idea.sbt,plugins.sbt,metals.sbt ...                          
[info] Loading global plugins from /home/mhogerheijde/.sbt/1.0/plugins                                               
[info] Loading settings for project test-build from plugins.sbt ...                                                  
[info] Loading project definition from /home/mhogerheijde/workspace/test/project                               
[info] Loading settings for project test from build.sbt ...                                                          
[info] Set current project to test (in build file:/home/mhogerheijde/workspace/test/)                          
[info] No dependency updates found for test
[info] No dependency updates found for dependencies
[success] Total time: 0 s, completed Sep 23, 2019, 11:06:13 AM                                                       
sbt dependencyUpdates  30.36s user 1.80s system 481% cpu 6.680 total              

When I remove the line with the credentials set up, the expected output is:

➜ sbt dependencyUpdates
[info] Loading settings for project global-plugins from idea.sbt,plugins.sbt,metals.sbt ...                          
[info] Loading global plugins from /home/mhogerheijde/.sbt/1.0/plugins                                               
[info] Loading settings for project test-build from plugins.sbt ...                                                  
[info] Loading project definition from /home/mhogerheijde/workspace-husky/test/project                               
[info] Loading settings for project test from build.sbt ...                                                          
[info] Set current project to test (in build file:/home/mhogerheijde/workspace-husky/test/)                          
[info] Found 1 dependency update for test
[info]   org.scala-lang:scala-library : 2.12.8 -> 2.12.10 -> 2.13.1                                                  
[info] Found 2 dependency updates for dependencies
[info]   com.github.ghik:silencer-lib : 1.3.1  -> 1.3.4   -> 1.4.2                                                   
[info]   org.scala-lang:scala-library : 2.12.8 -> 2.12.10 -> 2.13.1                                                  
[success] Total time: 0 s, completed Sep 23, 2019, 11:10:35 AM                                                       
sbt dependencyUpdates  34.40s user 1.89s system 493% cpu 7.358 total                  

Note that when I set up the configuration for actually pushing to our internal repo, I also get

[warn] Credentials file /var/jenkins_home/sbtCredentials.ini does not exist

But I'm not publishing to the repository and sbt can actually read (and compile etc.) when I add our private packages as dependencies.

mhogerheijde commented 5 years ago

Edited: corrected the expected output with the actual expected output instead of the copy-paste mistake I made

rtimush commented 5 years ago

@mhogerheijde, thank you for such a thorough bug report! I hope #125 has fixed the problem. Would be great if you could check whether it works for you:

resolvers += Resolver.bintrayIvyRepo("rtimush", "sbt-plugin-snapshots")
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.4.3-9-e0fa3dc")
mhogerheijde commented 5 years ago

@rtimush It works in the sense that I now do get the updates listed.

It does, however, now also throw RuntimeExceptions for the missing sbtCredentials.ini. (see output below).

I'm not fully sure if this is caused by the sbt-updates plugin itself, since the throw ultimately occurs in the sbt.librarymanagement.ivy package.

It might also be that I should test for the existence of the file before configuring it, but I'd rather not have too many if-statements in my build.

My build.sbt has 4 projects, so I assume the errors are multiplied by the number of projects since it tries to find the sbtCredentials.ini for every single project.

➜ sbt dependencyUpdates
[info] Loading settings for project global-plugins from idea.sbt,plugins.sbt,metals.sbt ...
[info] Loading global plugins from /home/mhogerheijde/.sbt/1.0/plugins
[info] Loading settings for project husky-convert-build from plugins.sbt ...
[info] Loading project definition from /home/mhogerheijde/workspace-husky/husky-convert/project
[info] Updating ProjectRef(uri("file:/home/mhogerheijde/workspace-husky/husky-convert/project/"), "husky-convert-build")...
[info] downloading https://dl.bintray.com/rtimush/sbt-plugin-snapshots/com.timushev.sbt/sbt-updates/scala_2.12/sbt_1.0/0.4.3-9-e0fa3dc/jars/sbt-updates.jar ...
[info]  [SUCCESSFUL ] com.timushev.sbt#sbt-updates;0.4.3-9-e0fa3dc!sbt-updates.jar (186ms)
[info] Done updating.
[warn] There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.
[info] Loading settings for project husky-convert from build.sbt ...
[info] Set current project to husky-convert (in build file:/home/mhogerheijde/workspace-husky/husky-convert/)
[warn] Credentials file /var/jenkins_home/sbtCredentials.ini does not exist
[warn] Credentials file /var/jenkins_home/sbtCredentials.ini does not exist
[warn] Credentials file /var/jenkins_home/sbtCredentials.ini does not exist

[~100 x a variation of the following stacktrace]

[error] java.lang.RuntimeException: Credentials file /var/jenkins_home/sbtCredentials.ini does not exist
[error]         at scala.sys.package$.error(package.scala:26)
[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.TraversableLike.$anonfun$map$1(TraversableLike.scala:233)
[error]         at scala.collection.immutable.List.foreach(List.scala:388)
[error]         at scala.collection.TraversableLike.map(TraversableLike.scala:233)
[error]         at scala.collection.TraversableLike.map$(TraversableLike.scala:226)
[error]         at scala.collection.immutable.List.map(List.scala:294)
[error]         at sbt.librarymanagement.ivy.Credentials$.allDirect(Credentials.scala:31)
[error]         at sbt.librarymanagement.ivy.Credentials$.forHost(Credentials.scala:30)
[error]         at com.timushev.sbt.updates.Downloader.$anonfun$startDownload$1(Downloader.scala:12)
[error]         at scala.util.control.Exception$Catch.$anonfun$either$1(Exception.scala:248)
[error]         at scala.util.control.Exception$Catch.apply(Exception.scala:224)
[error]         at scala.util.control.Exception$Catch.either(Exception.scala:248)
[error]         at com.timushev.sbt.updates.Downloader.startDownload(Downloader.scala:12)
[error]         at com.timushev.sbt.updates.metadata.MavenMetadataLoader.$anonfun$download$1(MavenMetadataLoader.scala:48)
[error]         at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:654)
[error]         at scala.util.Success.$anonfun$map$1(Try.scala:251)
[error]         at scala.util.Success.map(Try.scala:209)
[error]         at scala.concurrent.Future.$anonfun$map$1(Future.scala:288)
[error]         at scala.concurrent.impl.Promise.liftedTree1$1(Promise.scala:29)
[error]         at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:29)
[error]         at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60)
[error]         at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
[error]         at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
[error]         at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
[error]         at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
[error]         at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
[error]         at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:177)
[info] Found 2 dependency updates for random
[info]   org.scala-lang:scala-library : 2.12.8 -> 2.12.10 -> 2.13.1
[info]   org.scalacheck:scalacheck    : 1.14.1 -> 1.14.2
[info] Found 1 dependency update for husky-convert
[info]   org.scala-lang:scala-library : 2.12.8 -> 2.12.10 -> 2.13.1
[info] Found 1 dependency update for cli
[info]   org.scala-lang:scala-library : 2.12.8 -> 2.12.10 -> 2.13.1
[info] Found 1 dependency update for converterextra
[info]   org.scala-lang:scala-library : 2.12.8 -> 2.12.10 -> 2.13.1
[info] Found 2 dependency updates for converter
[info]   net.sf.saxon:Saxon-HE        : 9.9.1-3 -> 9.9.1-5
[info]   org.scala-lang:scala-library : 2.12.8  -> 2.12.10 -> 2.13.1
[success] Total time: 1 s, completed Sep 30, 2019, 9:30:21 AM
sbt dependencyUpdates  96.96s user 5.22s system 597% cpu 17.094 total
rtimush commented 5 years ago

Can you please try 0.4.3-10-409c548?

mhogerheijde commented 5 years ago

Works like a charm! Thanks!