Monday, November 26, 2012

Using custom libraries directly in SBT task code...

Using custom library directly in SBT task code is quite easy, just add your dependencies into project/plugins.sbt, and then your imports in built.sbt and that's all folk.

The following example shows how to use a custom SSH API (JASSH) to send an executable jar to a remote server :

import AssemblyKeys._
import jassh._

seq(assemblySettings: _*)

name := "MyProject"

version := "0.1"

scalaVersion := "2.10.0-RC2"

mainClass in assembly := Some("com.mycompany.myproject.Main")

jarName in assembly := "myproject.jar"


...


TaskKey[Unit]("export", "Send 2 server")<<= (assembly in assembly) map { jarfile=>
  SSH.once(host="localhost", username="test") { ssh =>
    println("Exporting %s on %s".format(jarfile.getPath, ssh.execute("hostname")))
    ssh.send(jarfile.getPath, jarfile.getName)
  }
}

The content of SBT project/plugins.sbt :
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.0")

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.8.4")

libraryDependencies += "fr.janalyse" %% "janalyse-ssh" % "0.9.5-b3" % "compile"

resolvers += "JAnalyse repository" at "http://www.janalyse.fr/repository/"

It is worth noting that dependency management system is used both for your project and for your build specification.

No comments:

Post a Comment