如何在 CircleCI 上添加 SBT 插件解析器?

How do I add an SBT plugin resolver on CircleCI?

我正在尝试使用 CircleCI 自动化 CI/CD 一个小型 Scala 项目。该项目使用 sbt 构建,并使用 ScalaTest 库进行测试。

根据 ScalaTest installation instruction's 的建议,我正在使用 SuperSafe 编译器插件,这需要我向全局文件添加解析器 ~/.sbt/1.0/global.sbt:

resolvers += "Artima Maven Repository" at "http://repo.artima.com/releases"

我可以在本地成功编译和测试我的项目。然而在 CircleCI 上构建失败并出现错误:

[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: com.artima.supersafe#supersafe_2.12.8;1.1.7: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn] 
[warn]  Note: Unresolved dependencies path:
[warn]      com.artima.supersafe:supersafe_2.12.8:1.1.7 (Defaults.scala#L3331)
[warn]        +- filesystem:filesystem_2.12:0.1
[error] sbt.librarymanagement.ResolveException: unresolved dependency: com.artima.supersafe#supersafe_2.12.8;1.1.7: not found
[error]     at sbt.internal.librarymanagement.IvyActions$.resolveAndRetrieve(IvyActions.scala:332)
[error]     at sbt.internal.librarymanagement.IvyActions$.$anonfun$updateEither(IvyActions.scala:208)
[error]     at sbt.internal.librarymanagement.IvySbt$Module.$anonfun$withModule(Ivy.scala:239)
[error]     at sbt.internal.librarymanagement.IvySbt.$anonfun$withIvy(Ivy.scala:204)
[error]     at sbt.internal.librarymanagement.IvySbt.sbt$internal$librarymanagement$IvySbt$$action(Ivy.scala:70)
[error]     at sbt.internal.librarymanagement.IvySbt$$anon.call(Ivy.scala:77)
[error]     at xsbt.boot.Locks$GlobalLock.withChannel(Locks.scala:95)
[error]     at xsbt.boot.Locks$GlobalLock.xsbt$boot$Locks$GlobalLock$$withChannelRetries(Locks.scala:80)
[error]     at xsbt.boot.Locks$GlobalLock$$anonfun$withFileLock.apply(Locks.scala:99)
[error]     at xsbt.boot.Using$.withResource(Using.scala:10)
[error]     at xsbt.boot.Using$.apply(Using.scala:9)
[error]     at xsbt.boot.Locks$GlobalLock.ignoringDeadlockAvoided(Locks.scala:60)
[error]     at xsbt.boot.Locks$GlobalLock.withLock(Locks.scala:50)
[error]     at xsbt.boot.Locks$.apply0(Locks.scala:31)
[error]     at xsbt.boot.Locks$.apply(Locks.scala:28)
[error]     at sbt.internal.librarymanagement.IvySbt.withDefaultLogger(Ivy.scala:77)
[error]     at sbt.internal.librarymanagement.IvySbt.withIvy(Ivy.scala:199)
[error]     at sbt.internal.librarymanagement.IvySbt.withIvy(Ivy.scala:196)
[error]     at sbt.internal.librarymanagement.IvySbt$Module.withModule(Ivy.scala:238)
[error]     at sbt.internal.librarymanagement.IvyActions$.updateEither(IvyActions.scala:193)
[error]     at sbt.librarymanagement.ivy.IvyDependencyResolution.update(IvyDependencyResolution.scala:20)
[error]     at sbt.librarymanagement.DependencyResolution.update(DependencyResolution.scala:56)
[error]     at sbt.internal.LibraryManagement$.resolve(LibraryManagement.scala:45)
[error]     at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate(LibraryManagement.scala:93)
[error]     at sbt.util.Tracked$.$anonfun$lastOutput(Tracked.scala:68)
[error]     at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate(LibraryManagement.scala:106)
[error]     at scala.util.control.Exception$Catch.apply(Exception.scala:224)
[error]     at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate(LibraryManagement.scala:106)
[error]     at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$adapted(LibraryManagement.scala:89)
[error]     at sbt.util.Tracked$.$anonfun$inputChanged(Tracked.scala:149)
[error]     at sbt.internal.LibraryManagement$.cachedUpdate(LibraryManagement.scala:120)
[error]     at sbt.Classpaths$.$anonfun$updateTask(Defaults.scala:2561)
[error]     at scala.Function1.$anonfun$compose(Function1.scala:44)
[error]     at sbt.internal.util.$tilde$greater.$anonfun$$u2219(TypeFunctions.scala:40)
[error]     at sbt.std.Transform$$anon.work(System.scala:67)
[error]     at sbt.Execute.$anonfun$submit(Execute.scala:269)
[error]     at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error]     at sbt.Execute.work(Execute.scala:278)
[error]     at sbt.Execute.$anonfun$submit(Execute.scala:269)
[error]     at sbt.ConcurrentRestrictions$$anon.$anonfun$submitValid(ConcurrentRestrictions.scala:178)
[error]     at sbt.CompletionService$$anon.call(CompletionService.scala:37)
[error]     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error]     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[error]     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[error]     at java.lang.Thread.run(Thread.java:748)
[error] (update) sbt.librarymanagement.ResolveException: unresolved dependency: com.artima.supersafe#supersafe_2.12.8;1.1.7: not found

当 SBT 中没有添加所需的解析器时,这个错误是预料之中的——参见例如。我是 CircleCI 的新手,不知道它的 SBT 全局目录在哪里,或者如何修改文件。

相反,我尝试将解析器直接添加到我项目的 ./project/plugins.sbt 文件中,但这并没有解决问题。

SBT 和 CircleCI 配置文件如下所示:

./build.sbt

name := "my-project-name"

version := "0.1"

scalaVersion := "2.12.8"

libraryDependencies += "org.scalactic" %% "scalactic" % "3.0.8"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.8" % "test"

./project/build.properties

sbt.version = 1.2.8

./project/plugins.sbt

resolvers += "Artima Maven Repository" at "http://repo.artima.com/releases"

addSbtPlugin("com.artima.supersafe" % "sbtplugin" % "1.1.7")

./.circleci/config.yml (CircleCI 提供的默认 Scala 配置)

# Scala CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/sample-config/ for more details
#
version: 2
jobs:
  build:
    docker:
      # specify the version you desire here
      - image: circleci/openjdk:8-jdk

      # Specify service dependencies here if necessary
      # CircleCI maintains a library of pre-built images
      # documented at https://circleci.com/docs/2.0/circleci-images/
      # - image: circleci/postgres:9.4

    working_directory: ~/repo

    environment:
      # Customize the JVM maximum heap limit
      JVM_OPTS: -Xmx3200m
      TERM: dumb

    steps:
      - checkout

      # Download and cache dependencies
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "build.sbt" }}
            # fallback to using the latest cache if no exact match is found
            - v1-dependencies-

      - run: cat /dev/null | sbt test:compile

      - save_cache:
          paths:
            - ~/.m2
          key: v1-dependencies--{{ checksum "build.sbt" }}

      # run tests!
      - run: cat /dev/null | sbt test:test

我想要一个成功的 CircleCI 构建,这将需要一种方法来添加解析器,要么在项目自己的文件中,要么在 CircleCI 容器的 SBT 全局文件中声明它。

考虑未决问题 SBT isn't using resolvers defined in project/plugins.sbt #4103。尝试将解析器的范围限定为 ThisBuild 并将其放入 both build.sbtplugins.sbt 中,如下所示:

// someApp/build.sbt
resolvers in ThisBuild += "Artima Maven Repository" at "http://repo.artima.com/releases"

// someApp/project/plugins.sbt
resolvers in ThisBuild += "Artima Maven Repository" at "http://repo.artima.com/releases"
addSbtPlugin("com.artima.supersafe" % "sbtplugin" % "1.1.7")

这似乎适用于此示例 repo