Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a github java dependency in sbt config?

Tags:

github

scala

sbt

I've added this code to my Build.scala.

  lazy val root = Project("root", file(".")) dependsOn(jbcrypt)
  lazy val jbcrypt = RootProject(uri("https://github.com/jeremyh/jBCrypt.git"))

But sbt fails with the error:

[error] (root/*:update) sbt.ResolveException: unresolved dependency: default#jbcrypt_2.11;0.1-SNAPSHOT: not found

How to tell sbt that it is Java not Scala?

How to reference to a specific branch or tag?

Thank you.

like image 400
kikulikov Avatar asked Apr 04 '15 16:04

kikulikov


People also ask

What dependencies does SBT use?

Under the covers, SBT uses Apache Ivy as its dependency manager. Ivy is also used by Ant and Maven, and as a result, you can easily use the wealth of Java libraries that have been created over the years in your Scala projects. There are two general forms for adding a managed dependency to a build.sbt file.

How do I add a Java agent to a sbt project?

Java agent. To add a Java agent to an sbt-native-packager distribution, enable the JavaAgent plugin on a project that also has JavaAppPackaging enabled, and then add the agent dependency using the javaAgents setting.

Can I use jar files in SBT projects?

You can use both managed and unmanaged dependencies in your SBT projects. If you have JAR files (unmanaged dependencies) that you want to use in your project, simply copy them to the lib folder in the root directory of your SBT project, and SBT will find them automatically.

Can I use external libraries in my SBT projects?

You want to use one or more external libraries (dependencies) in your Scala /SBT projects. You can use both managed and unmanaged dependencies in your SBT projects.


1 Answers

Building a project from source is only possible if the referenced project is a sbt project. sbt doesn't know of all the different build systems out there, so how is it supposed to know how to build a non sbt project?

It is possible to add support for other build systems through a sbt plugin but this may be a lot of work.

Your referenced project is a simple Maven project, which means that you can easily create a sbt project from it. Just fork the repo and create a build.sbt with the following content:

scalaVersion := "2.11.5"

projectDependencies += "junit" % "junit" % "3.8.1" % "test"

publishTo := {
  val nexus = "https://oss.sonatype.org/"
  if (isSnapshot.value) Some("snapshots" at nexus + "content/repositories/snapshots")
  else Some("releases" at nexus + "service/local/staging/deploy/maven2")
}

This is the minimal code that was necessary to get it up and running. sbt seems to require that a publish repo is specified, it also seems to require an explicit Scala version. The dependency is already specified by your linked Maven project.

Of course, you know need to change the URI of RootProject to point to the location of your fork.

To your second question: You can reference a commit/tag/branch by appending it to the URI, separated with a # sign:

uri("git://github.com/your/repo#<commit-hash/tag/branch>")
like image 181
kiritsuku Avatar answered Sep 23 '22 11:09

kiritsuku