SBT|如何禁用或避免 .sbt/preloaded

SBT | how to disable or avoid .sbt/preloaded

我正在尝试使用 sbt 将依赖项集成到我的 lagom 项目中。我为此使用的版本是:

// The Lagom plugin
addSbtPlugin("com.lightbend.lagom" % "lagom-sbt-plugin" % "1.3.7")
// Needed for importing the project into Eclipse
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "5.1.0")
sbt.version=0.13.16
scala=2.11.7

这是我留在 scala 2.11.7 上的服务要求,尽管我们期待尽快升级它,但这至少需要 6 个月的时间。

我要集成的依赖项是

"com.example" % "example-models_2.11" % "1.0.0-SNAPSHOT"
val nexus_url = "https://company-repo.example.com/"
credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")

resolvers += "Nexus" at s"$nexus_url/repository/example-repo/"

问题

出于某种原因,它没有尝试我的 nexus 存储库,而是尝试:

[info] Resolving com.example#example-models_2.11;1.0.0-SNAPSHOT ...
[warn]  module not found: com.example#example-models_2.11;1.0.0-SNAPSHOT
[warn] ==== local: tried
[warn]   /home/yash/.ivy2/local/com.example/example-models_2.11/1.0.0-SNAPSHOT/ivys/ivy.xml
[warn] ==== public: tried
[warn]   https://repo1.maven.org/maven2/com/example/example-models_2.11/1.0.0-SNAPSHOT/example-models_2.11-1.0.0-SNAPSHOT.pom
[warn] ==== local-preloaded-ivy: tried
[warn]   /home/yash/.sbt/preloaded/com.example/example-models_2.11/1.0.0-SNAPSHOT/ivys/ivy.xml
[warn] ==== local-preloaded: tried
[warn]   file:////home/yash/.sbt/preloaded/com/example/example-models_2.11/1.0.0-SNAPSHOT/example-models_2.11-1.0.0-SNAPSHOT.pom
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: com.example#example-models_2.11;1.0.0-SNAPSHOT: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn] 
[warn]  Note: Unresolved dependencies path:
[warn]      com.example:example-models_2.11:1.0.0-SNAPSHOT (/home/yash/development/example/build.sbt#L21)
[warn]        +- com.example:example-impl_2.11:1.0.0-SNAPSHOT
[info] 'compiler-interface' not yet compiled for Scala 2.11.7. Compiling...
[info]   Compilation completed in 8.811 s
sbt.ResolveException: unresolved dependency: com.example#example-models_2.11;1.0.0-SNAPSHOT: not found
    at sbt.IvyActions$.sbt$IvyActions$$resolve(IvyActions.scala:313)
    at sbt.IvyActions$$anonfun$updateEither.apply(IvyActions.scala:191)
    at sbt.IvyActions$$anonfun$updateEither.apply(IvyActions.scala:168)
    at sbt.IvySbt$Module$$anonfun$withModule.apply(Ivy.scala:156)
    at sbt.IvySbt$Module$$anonfun$withModule.apply(Ivy.scala:156)
    at sbt.IvySbt$$anonfun$withIvy.apply(Ivy.scala:133)
    at sbt.IvySbt.sbt$IvySbt$$action(Ivy.scala:57)
    at sbt.IvySbt$$anon.call(Ivy.scala:65)
    at xsbt.boot.Locks$GlobalLock.withChannel(Locks.scala:95)
    at xsbt.boot.Locks$GlobalLock.xsbt$boot$Locks$GlobalLock$$withChannelRetries(Locks.scala:80)
    at xsbt.boot.Locks$GlobalLock$$anonfun$withFileLock.apply(Locks.scala:99)
    at xsbt.boot.Using$.withResource(Using.scala:10)
    at xsbt.boot.Using$.apply(Using.scala:9)
    at xsbt.boot.Locks$GlobalLock.ignoringDeadlockAvoided(Locks.scala:60)
    at xsbt.boot.Locks$GlobalLock.withLock(Locks.scala:50)
    at xsbt.boot.Locks$.apply0(Locks.scala:31)
    at xsbt.boot.Locks$.apply(Locks.scala:28)
    at sbt.IvySbt.withDefaultLogger(Ivy.scala:65)
    at sbt.IvySbt.withIvy(Ivy.scala:128)
    at sbt.IvySbt.withIvy(Ivy.scala:125)
    at sbt.IvySbt$Module.withModule(Ivy.scala:156)
    at sbt.IvyActions$.updateEither(IvyActions.scala:168)
    at sbt.Classpaths$$anonfun$sbt$Classpaths$$work.apply(Defaults.scala:1541)
    at sbt.Classpaths$$anonfun$sbt$Classpaths$$work.apply(Defaults.scala:1537)
    at sbt.Classpaths$$anonfun$doWork$$anonfun1.apply(Defaults.scala:1572)
    at sbt.Classpaths$$anonfun$doWork$$anonfun1.apply(Defaults.scala:1570)
    at sbt.Tracked$$anonfun$lastOutput.apply(Tracked.scala:37)
    at sbt.Classpaths$$anonfun$doWork.apply(Defaults.scala:1575)
    at sbt.Classpaths$$anonfun$doWork.apply(Defaults.scala:1569)
    at sbt.Tracked$$anonfun$inputChanged.apply(Tracked.scala:60)
    at sbt.Classpaths$.cachedUpdate(Defaults.scala:1592)
    at sbt.Classpaths$$anonfun$updateTask.apply(Defaults.scala:1519)
    at sbt.Classpaths$$anonfun$updateTask.apply(Defaults.scala:1471)
    at scala.Function1$$anonfun$compose.apply(Function1.scala:47)
    at sbt.$tilde$greater$$anonfun$$u2219.apply(TypeFunctions.scala:40)
    at sbt.std.Transform$$anon.work(System.scala:63)
    at sbt.Execute$$anonfun$submit$$anonfun$apply.apply(Execute.scala:228)
    at sbt.Execute$$anonfun$submit$$anonfun$apply.apply(Execute.scala:228)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
    at sbt.Execute.work(Execute.scala:237)
    at sbt.Execute$$anonfun$submit.apply(Execute.scala:228)
    at sbt.Execute$$anonfun$submit.apply(Execute.scala:228)
    at sbt.ConcurrentRestrictions$$anon$$anonfun.apply(ConcurrentRestrictions.scala:159)
    at sbt.CompletionService$$anon.call(CompletionService.scala:28)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
[error] (lms-impl/*:update) sbt.ResolveException: unresolved dependency: com.example#example-models_2.11;1.0.0-SNAPSHOT: not found
[error] Total time: 876 s, completed Dec 5, 2018 1:36:18 PM

https://github.com/sbt/sbt/issues/4015 and https://github.com/sbt/librarymanagement/issues/224 之类的讨论没有帮助。

在下面的评论中,Vanya Stanislavciuc 提出了一个关于解析器的好问题,感谢您提出这个问题。

现在这似乎比 sbt 更 Lagom 问题,所以我 运行 给定的命令:

[info] Loading project definition from /home/yash/development/LF_Repos/loanframe-services/lf-lms/project
[info] Set current project to lf-lms (in build file:/home/yash/development/LF_Repos/loanframe-services/lf-lms/)
[info] lms-api/*:resolvers
[info]  List()
[info] lms-impl/*:resolvers
[info]  List()
[info] lms/*:resolvers
[info]  List()

然后我看到了如何在 Lagom 中提供解析器,因为它忽略了 sbt 解析器,所以我以 Lagom 的方式添加了它:

lazy val `example-impl` = (project in file("example-impl"))
  .enablePlugins(LagomScala)
  .settings(
    libraryDependencies ++= Seq(
      lagomScaladslPersistenceCassandra,
      lagomScaladslKafkaBroker,
      lagomScaladslTestKit,
      lagomScaladslPersistenceJdbc,
      "com.softwaremill.macwire"    %%     "macros"               %     "2.3.0"     %     "provided",
      "org.scalatest"               %%     "scalatest"            %     "3.0.1"     %     Test,
      "com.amazonaws"               %      "aws-java-sdk-s3"      %     "1.11.117",
      "com.amazonaws"               %      "aws-java-sdk-sqs"     %     "1.11.456",
      "com.google.code.gson"        %      "gson"                 %     "2.8.1",
      "com.typesafe.slick"          %%     "slick"                %     "3.2.3",
      "com.example"               %      "example-models_2.11"  % "1.0.0-SNAPSHOT"
    ),
    resolvers += "Nexus" at s"$nexus_url/repository/example-repo/"
  )
  .settings(lagomForkedTestSettings: _*)
  .dependsOn(`example-api`)

它出现了:

[info] Loading project definition from /home/yash/development/LF_Repos/loanframe-services/lf-lms/project
[info] Set current project to lf-lms (in build file:/home/yash/development/LF_Repos/loanframe-services/lf-lms/)
[info] lms-api/*:resolvers
[info]  List()
[info] lms-impl/*:resolvers
[info]  List(Nexus: https://staging-repo.loanframe.com//repository/lf-repo/)
[info] lms/*:resolvers
[info]  List(scalaz-bintray: http://dl.bintray.com/scalaz/releases, URLRepository(Typesafe Ivy releases,Patterns(ivyPatterns=List(https://repo.typesafe.com/typesafe/ivy-releases/[organisation]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]), artifactPatterns=List(https://repo.typesafe.com/typesafe/ivy-releases/[organisation]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]), isMavenCompatible=false, descriptorOptional=false, skipConsistencyCheck=false)), Nexus: https://staging-repo.loanframe.com//repository/lf-repo/)

问题可能与 resolvers 键的 Scope/Configuration 有关。

您可以尝试添加 ThisBuild 配置,看看是否也有帮助吗?

resolvers in ThisBuild += "Nexus" at s"$nexus_url/repository/example-repo/"

lazy val `example-impl` = (project in file("example-impl"))
  .enablePlugins(LagomScala)
  .settings(
  resolvers += "Nexus" at s"$nexus_url/repository/example-repo/",
  credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")
  )
  .settings(
    libraryDependencies ++= Seq(
      lagomScaladslPersistenceCassandra,
      lagomScaladslKafkaBroker,
      lagomScaladslTestKit,
      lagomScaladslPersistenceJdbc,
    --dependencies--
   )
  )
  .settings(lagomForkedTestSettings: _*)
  .dependsOn(`example-api`)