Skip to content
Martin Krasser edited this page Oct 24, 2013 · 51 revisions

The following steps require sbt 0.12.1 or higher.

Build definition

### Released versions

Eventsourced 0.6.0 for Akka 2.2.0 and Scala 2.10.2

scalaVersion := "2.10.2"

resolvers += "Eligosource Releases" at "http://repo.eligotech.com/nexus/content/repositories/eligosource-releases"

libraryDependencies += "org.eligosource" %% "eventsourced-core" % "0.6.0"

// distributed journal implementations to choose from:

libraryDependencies += "org.eligosource" %% "eventsourced-journal-dynamodb" % "0.6.0"

libraryDependencies += "org.eligosource" %% "eventsourced-journal-hbase" % "0.6.0"

libraryDependencies += "org.eligosource" %% "eventsourced-journal-mongodb-casbah" % "0.6.0"

libraryDependencies += "org.eligosource" %% "eventsourced-journal-mongodb-reactive" % "0.6.0"

// local journal implementations to choose from:

libraryDependencies += "org.eligosource" %% "eventsourced-journal-journalio" % "0.6.0"

libraryDependencies += "org.eligosource" %% "eventsourced-journal-leveldb" % "0.6.0"

libraryDependencies += "org.eligosource" %% "eventsourced-journal-inmem" % "0.6.0"

// ...

To add eventsourced to your maven project, use http://repo.eligotech.com/nexus/content/repositories/eligosource-releases/ as a repository and add the following as dependencies to your pom.xml:

<dependency>
	<groupId>org.eligosource</groupId>
	<artifactId>eventsourced-core_2.10</artifactId>
	<version>0.6.0</version>
</dependency>
<dependency>
	<groupId>org.eligosource</groupId>
	<artifactId>eventsourced-journal-inmem_2.10</artifactId>
	<version>0.6.0</version>
</dependency>
<dependency>
	<groupId>org.eligosource</groupId>
	<artifactId>eventsourced-journal-leveldb_2.10</artifactId>
	<version>0.6.0</version>
</dependency>
<dependency>
	<groupId>org.eligosource</groupId>
	<artifactId>eventsourced-journal-journalio_2.10</artifactId>
	<version>0.6.0</version>
</dependency>
    <!-- further journal dependencies here ... --> 
<dependency>
	<groupId>org.scala-lang</groupId>
	<artifactId>scala-library</artifactId>
	<version>2.10.2</version>
</dependency>
### Development versions

Eventsourced 0.7-SNAPSHOT for Akka 2.2.0 and Scala 2.10.2

scalaVersion := "2.10.2"

resolvers += "Eligosource Snapshots" at "http://repo.eligotech.com/nexus/content/repositories/eligosource-snapshots"

libraryDependencies += "org.eligosource" %% "eventsourced-core" % "0.7-SNAPSHOT"

// distributed journal implementations to choose from:

libraryDependencies += "org.eligosource" %% "eventsourced-journal-dynamodb" % "0.7-SNAPSHOT"

libraryDependencies += "org.eligosource" %% "eventsourced-journal-hbase" % "0.7-SNAPSHOT"

libraryDependencies += "org.eligosource" %% "eventsourced-journal-mongodb-casbah" % "0.7-SNAPSHOT"

libraryDependencies += "org.eligosource" %% "eventsourced-journal-mongodb-reactive" % "0.7-SNAPSHOT"

// local journal implementations to choose from:

libraryDependencies += "org.eligosource" %% "eventsourced-journal-journalio" % "0.7-SNAPSHOT"

libraryDependencies += "org.eligosource" %% "eventsourced-journal-leveldb" % "0.7-SNAPSHOT"

libraryDependencies += "org.eligosource" %% "eventsourced-journal-inmem" % "0.7-SNAPSHOT"

// ...

Running LevelDB

By default, a LevelDB journal runs a native LevelDB instance which requires special setting in your sbt project, as described in section Native LevelDB. If you'd rather like to avoid running native code you can also use a LevelDB Java port, as described in the next section.

LevelDB Java port

To run the LevelDB Java port, a LevelDB journal must be configured with native = false. This option is available since eventsourced 0.6.

import java.io.File

import org.eligosource.eventsourced.core._
import org.eligosource.eventsourced.journal.leveldb.LeveldbJournalProps

val journalDir: File = ...
val journal = Journal(LeveldbJournalProps(journalDir, native = false))
#### Native LevelDB

Running native libraries from within an sbt project may have some issues as described in sbt issue #358. To get a native LevelDB running in your sbt project, a few additional steps are required. The following example adds two new custom tasks, run-nobootcp and test:run-nobootcp to your project's Build.scala file. They are equivalent to sbt's default run-main and test:run-main tasks but do not add the Scala library to the boot classpath.

import sbt._
import Keys._

object MyBuild extends Build {
  ...

  lazy val myProject = Project(
    id = "myProject",
    base = file("."),
    settings = Defaults.defaultSettings ++ Seq(
      ...,
      mainRunNobootcpSetting,
      testRunNobootcpSetting
    )
  )

  val runNobootcp =
    InputKey[Unit]("run-nobootcp", "Runs main classes without Scala library on the boot classpath")

  val mainRunNobootcpSetting = runNobootcp <<= runNobootcpInputTask(Runtime)
  val testRunNobootcpSetting = runNobootcp <<= runNobootcpInputTask(Test)


  def runNobootcpInputTask(configuration: Configuration) = inputTask {
    (argTask: TaskKey[Seq[String]]) => (argTask, streams, fullClasspath in configuration) map { (at, st, cp) =>
      val runCp = cp.map(_.data).mkString(pathSeparator)
      val runOpts = Seq("-classpath", runCp) ++ at
      val result = Fork.java.fork(None, runOpts, None, Map(), false, LoggedOutput(st.log)).exitValue()
      if (result != 0) error("Run failed")
    }
  }
}

Use these new tasks to run main classes that use the library's LevelDB-based journal. For example, to run the main class org.example.MyClass (compiled from sources under src/main/scala) execute

sbt 'run-nobootcp org.example.MyClass'

To get LevelDB running within your tests, you'll need to start your testing framework without the Scala library on the boot classpath. This project's Build.scala file demonstrates how this can be done for ScalaTest, another example demonstrates how this can be done for Specs2.

Clone this wiki locally