【问题标题】:Adding dependencies to a Scala project (sbt)将依赖项添加到 Scala 项目 (sbt)
【发布时间】:2013-05-28 14:29:58
【问题描述】:

我想在 Scala 项目中使用 https://github.com/randhindi/jerkson 的库。我可能会在位于项目的基本目录中的build.sbt 中添加类似这样的内容:

libraryDependencies += "com.domain_example" % "library_name_test123" % "0.1.1"

但是我从哪里获得所有这些数据:域名、库名称、版本? https://github.com/randhindi/jerkson没有这样的数据

那么我需要做什么才能使用它?

【问题讨论】:

    标签: java scala github dependencies sbt


    【解决方案1】:

    这是 Typesafe 存储库的链接,这是 Typesafe 维护的官方repository

    在搜索框中输入 jerkson,它将显示存储库中托管的所有相关项目。

    应该可以看到路径,比如:

    com/codahale/jerkson_2.8.2/0.5.0
    

    您可以将其分解为 3 个组件。

    试试这个:

    libraryDependencies += "com.codahale" % "jerkson_2.8.2" % "0.5.0"
    

    如果你想要最新的集成,你可以使用latest.integration作为第三个参数

    libraryDependencies += "com.codahale" % "jerkson_2.8.2" % "latest.integration"
    

    一般来说,我会先尝试 Maven 存储库

    Here's Maven 仓库是什么样子的:

    这很好,因为您可以看到 sbt 的选项卡,您可以简单地将其复制到您的代码中。不幸的是,我在 Maven 中没有看到你想要的库。

    【讨论】:

    • 我认为我在回答中提到的jerkson项目与github.com/randhindi/jerkson有关。如果您查看https://github.com/randhindi/jerkson/blob/master/src/main/java/com/codahale/jerkson/JsonSnakeCase.java 的包装声明,我认为它们是相同的。
    • 但是你从哪里得到所有这些数据"com.codahale" % "jerkson_2.8.2" % "0.5.0",它写在哪里?
    • 我已经更新了我的答案。你需要做的是点击[typesafe repo] (repo.typesafe.com/typesafe/webapp/browserepo.html?2),在搜索框中输入jerkson,会显示jerkson相关项目的列表。
    • 是 Maven 存储库被认为是我应该尝试查找依赖项的第一个“官方”位置吗?
    • 官方的一个是Typesafe repository。见这里:(playframework.com/documentation/2.1.1/Repositories)。顺便说一句,我的回答解决了你的问题吗?
    【解决方案2】:

    根据您对其他答案的 cmets,我相信您希望做的是直接指定对 github URL 的依赖关系。这是asked before。两个答案都是正确的,应该证明对您有用。

    【讨论】:

      【解决方案3】:

      如果您不想调查构建配置,那么您可以克隆存储库并执行publish-local。会有神器信息。您还可以将工件添加到本地 Ivy 存储库。在这种情况下:

      [info]  published jerkson_2.10 to /home/ezh/.ivy2/local/jerkson/jerkson_2.10/0.1-SNAPSHOT/...
      

      你的情况

      "jerkson" %% "jerkson" % "0.1-SNAPSHOT"
      

      "jerkson" % "jerkson_2.10" % "0.1-SNAPSHOT"
      

      针对 Scala 2.10 构建的库

      完整日志:

      ezh@devbox ~/ze $ git clone https://github.com/randhindi/jerkson.git
      Cloning into 'jerkson'...
      remote: Counting objects: 3093, done.
      remote: Compressing objects: 100% (1203/1203), done.
      remote: Total 3093 (delta 984), reused 2863 (delta 790)
      Receiving objects: 100% (3093/3093), 436.47 KiB | 177 KiB/s, done.
      Resolving deltas: 100% (984/984), done.
      ezh@devbox ~/ze $ cd jerkson/
      ezh@devbox ~/ze/jerkson $ sbt-0.12 publish-local
      [info] Loading project definition from /home/ezh/ze/jerkson/project
      [info] Updating {file:/home/ezh/ze/jerkson/project/}default-b33f9c...
      [info] Resolving org.scala-sbt#precompiled-2_10_1;0.12.4-RC1 ...
      [info] Done updating.
      [info] Compiling 1 Scala source to /home/ezh/ze/jerkson/project/target/scala-2.9.2/sbt-0.12/classes...
      [info] Set current project to jerkson (in build file:/home/ezh/ze/jerkson/)
      [info] Updating {file:/home/ezh/ze/jerkson/}jerkson...
      [info] Packaging /home/ezh/ze/jerkson/target/scala-2.10/jerkson_2.10-0.1-SNAPSHOT-sources.jar ...
      [info] Wrote /home/ezh/ze/jerkson/target/scala-2.10/jerkson_2.10-0.1-SNAPSHOT.pom
      [info] Resolving org.scala-lang#scala-library;2.10.0 ...
      [info] Done packaging.
      [info] Resolving org.hamcrest#hamcrest-core;1.1 ...
      [info] downloading http://oss.sonatype.org/content/groups/public/com/fasterxml/jackson/core/jackson-core/2.1.1/jackson-core-2.1.1.jar ...
      [info]  [SUCCESSFUL ] com.fasterxml.jackson.core#jackson-core;2.1.1!jackson-core.jar (2325ms)
      [info] downloading http://oss.sonatype.org/content/groups/public/com/fasterxml/jackson/core/jackson-databind/2.1.1/jackson-databind-2.1.1.jar ...
      [info]  [SUCCESSFUL ] com.fasterxml.jackson.core#jackson-databind;2.1.1!jackson-databind.jar (2351ms)
      [info] downloading http://oss.sonatype.org/content/groups/public/org/mockito/mockito-all/1.9.0/mockito-all-1.9.0.jar ...
      [info]  [SUCCESSFUL ] org.mockito#mockito-all;1.9.0!mockito-all.jar (7677ms)
      [info] downloading http://oss.sonatype.org/content/groups/public/junit/junit/4.10/junit-4.10.jar ...
      [info]  [SUCCESSFUL ] junit#junit;4.10!junit.jar (1337ms)
      [info] downloading http://oss.sonatype.org/content/groups/public/com/fasterxml/jackson/core/jackson-annotations/2.1.1/jackson-annotations-2.1.1.jar ...
      [info]  [SUCCESSFUL ] com.fasterxml.jackson.core#jackson-annotations;2.1.1!jackson-annotations.jar (1384ms)                                                                                   
      [info] Done updating.                                                                                                                                                                         
      [info] :: delivering :: jerkson#jerkson_2.10;0.1-SNAPSHOT :: 0.1-SNAPSHOT :: integration :: Sun Jun 02 09:22:19 MSK 2013                                                                      
      [info]  delivering ivy file to /home/ezh/ze/jerkson/target/scala-2.10/ivy-0.1-SNAPSHOT.xml                                                                                                    
      [info] Compiling 77 Scala sources and 1 Java source to /home/ezh/ze/jerkson/target/scala-2.10/classes...                                                                                      
      [info] Generating Scala API documentation for main sources to /home/ezh/ze/jerkson/target/scala-2.10/api...                                                                                   
      [info] 'compiler-interface' not yet compiled for Scala 2.10.0. Compiling...                                                                                                                   
      [info]   Compilation completed in 10.168 s                                                                                                                                                    
      [warn] there were 51 feature warnings; re-run with -feature for details                                                                                                                       
      model contains 312 documentable templates                                                                                                                                                     
      [warn] /home/ezh/ze/jerkson/src/main/scala/com/codahale/jerkson/util/scalax/rules/Rules.scala:67: Tag '@requires' is not recognised                                                           
      [warn] /A factory for rules that apply to a particular context.                                                                                                                             
      [warn] ^                                                                                                                                                                                      
      [warn] two warnings found                                                                                                                                                                     
      [info] Scala API documentation generation successful.                                                                                                                                         
      [info] Packaging /home/ezh/ze/jerkson/target/scala-2.10/jerkson_2.10-0.1-SNAPSHOT-javadoc.jar ...                                                                                             
      [info] Done packaging.                                                                                                                                                                        
      [warn] there were 17 deprecation warnings; re-run with -deprecation for details                                                                                                               
      [warn] there were 1 unchecked warnings; re-run with -unchecked for details                                                                                                                    
      [warn] there were 51 feature warnings; re-run with -feature for details                                                                                                                       
      [warn] three warnings found
      [warn] Error reading API from class file : java.lang.UnsupportedClassVersionError: com/codahale/jerkson/JsonSnakeCase : Unsupported major.minor version 51.0
      [info] Packaging /home/ezh/ze/jerkson/target/scala-2.10/jerkson_2.10-0.1-SNAPSHOT.jar ...
      [info] Done packaging.
      [info]  published jerkson_2.10 to /home/ezh/.ivy2/local/jerkson/jerkson_2.10/0.1-SNAPSHOT/poms/jerkson_2.10.pom
      [info]  published jerkson_2.10 to /home/ezh/.ivy2/local/jerkson/jerkson_2.10/0.1-SNAPSHOT/jars/jerkson_2.10.jar
      [info]  published jerkson_2.10 to /home/ezh/.ivy2/local/jerkson/jerkson_2.10/0.1-SNAPSHOT/srcs/jerkson_2.10-sources.jar
      [info]  published jerkson_2.10 to /home/ezh/.ivy2/local/jerkson/jerkson_2.10/0.1-SNAPSHOT/docs/jerkson_2.10-javadoc.jar
      [info]  published ivy to /home/ezh/.ivy2/local/jerkson/jerkson_2.10/0.1-SNAPSHOT/ivys/ivy.xml
      [success] Total time: 56 s, completed 02.06.2013 9:22:48
      

      【讨论】:

      • 没关系。但我想从 githbu 使用它,我该怎么做,我怎么知道在 build.sbt 中写什么?
      • 我也在 GitHub 上使用它。我做git clone https://github.com/randhindi/jerkson.git。 “从 githbub 使用它”是什么意思?你想要一些特别的东西吗?
      • 我的意思是——没有克隆。
      • 没有工件是不可能的。如果您想在不克隆的情况下使用它,那么某人(randhindi?)必须将工件发布到 Ivy 或 Maven 目录结构并将其推送到 GitHub。请告诉我如何使用来自 GitHub 的原始、未编译的源代码作为依赖项?恕我直言,没有办法。甚至 SBT 本身在构建之前检查插件源代码。
      • 您可以在任何地方克隆它,但publish-local 将结果保存到位于您的主目录内的 .ivy2 目录(像往常一样)。
      猜你喜欢
      • 2015-03-30
      • 1970-01-01
      • 2012-04-22
      • 2018-01-13
      • 2020-01-20
      • 1970-01-01
      • 2013-12-06
      • 2019-04-11
      • 1970-01-01
      相关资源
      最近更新 更多