简体   繁体   English

使用 sbt 进行依赖解析以进行持续集成

[英]dependency resolution with sbt for continuous integration

I'm an open-source Scala developer who wants to minimize the hassle of dependencies when pushing to GitHub and triggering a check with continuous integration (CircleCI).我是一名开源 Scala 开发人员,希望在推送到 GitHub 并通过持续集成 (CircleCI) 触发检查时最大程度地减少依赖项的麻烦。 I have two projects where one (A) is dependent on the other (B).我有两个项目,其中一个(A)依赖于另一个(B)。 B is under development at the same time (as a snapshot). B 同时正在开发中(作为快照)。 My project A build.sbt file has a dependency on this (snapshot) version of B and of course all works fine on my local machine.我的项目 A build.sbt文件依赖于 B 的这个(快照)版本,当然在我的本地机器上一切正常。 When I push to GitHub, it naturally fails as that snapshot file is not available to CircleCI.当我推送到 GitHub 时,它自然会失败,因为 CircleCI 无法使用该快照文件。

I have generally worked around this by putting the jar file into my lib directory (and removing the dependency from build.sbt).我通常通过将 jar 文件放入我的 lib 目录(并从 build.sbt 中删除依赖项)来解决这个问题。 I believe this is known as an unmanaged dependency.我相信这被称为非托管依赖项。

My question is this: is there any way of setting up my lib directory so that CircleCI can resolve the (managed) dependency from the lib directory?我的问题是:有没有办法设置我的 lib 目录,以便 CircleCI 可以从 lib 目录解析(托管)依赖项? I have tried putting the ivy structure into lib starting with the top level com.phasmidsoftware, with b_2.13 under that and under that 1.0.4-SNAPSHOT and so on down.我曾尝试将 ivy 结构放入 lib 中,从顶级 com.phasmidsoftware 开始,然后是 b_2.13,然后是 1.0.4-SNAPSHOT 等等。 That doesn't work.那行不通。 I've attached the build.sbt for project A (called Numeric).我附上了项目 A(称为数字)的 build.sbt。

organization := "com.phasmidsoftware"

name := "Number"

version := "1.0.9"

scalaVersion := "2.13.6"

scalacOptions ++= Seq( "-target:jvm-1.8", "-encoding", "UTF-8", "-unchecked", "-deprecation", "-Ywarn-dead-code", "-Ywarn-value-discard", "-Ywarn-unused" )

val scalaTestVersion = "3.2.3"

libraryDependencies += "org.scalatest" %% "scalatest" % scalaTestVersion % "test"

resolvers += "Typesafe Repository" at "https://repo.typesafe.com/typesafe/releases/"

libraryDependencies ++= Seq(
  "com.phasmidsoftware" %% "matchers" % "1.0.4-SNAPSHOT",
  "org.scala-lang.modules" %% "scala-parser-combinators" % "1.2.0-M1",
  "org.apache.commons" % "commons-math3" % "3.6.1",
  "org.slf4j" % "slf4j-api" % "1.7.31",
  "ch.qos.logback" % "logback-classic" % "1.2.3" % "test",
  "org.scalacheck" %% "scalacheck" % "1.14.1" % "test"
)

The answer described in How can sbt pull dependency artifacts from git? How can sbt pull dependency artifacts from git? 中描述的答案 is indeed the right answer.确实是正确的答案。

I will just add a couple of caveats.我将添加一些警告。

  • Make sure that you use the git protocol in the URI of your git repository (as is shown in the other answer);确保在 git 存储库的 URI 中使用git协议(如另一个答案所示);
  • The mechanism works by cloning the repository (the branch is defined by ...#branch) but, once you've cloned it, sbt won't fetch if appropriate -- you do have to do that explicitly yourself.该机制通过克隆存储库(分支由 ...#branch 定义)来工作,但是,一旦您克隆了它,sbt 将不会在适当的情况下获取 - 您必须自己明确地这样做。
  • The other thing to keep in mind is that the clone(s) are placed in ~/.sbt/1.0/staging/... where 1.0 is based on the sbt version number.要记住的另一件事是,克隆放置在 ~/.sbt/1.0/staging/... 中,其中 1.0 基于 sbt 版本号。
  • And, of course, don't forget to remove the reference to the other project if you have it in your libraryDependencies.而且,当然,如果您的 libraryDependencies 中有其他项目的引用,请不要忘记删除它。

Here's the relevant part of my build.sbt file:这是我的build.sbt文件的相关部分:

lazy val root = (project in file(".")).dependsOn(matchers)
lazy val matchers = RootProject(uri("git://github.com/rchillyard/Matchers#V1_0_5"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM