Getting started

Get JaVers

JaVers artifacts are published to Maven Central. To get JaVers, add javers-core to your project dependencies and (optionally) choose proper javers-repository module.

javers-core

Gradle:

compile 'org.javers:javers-core:3.6.3'

Maven:

<dependency>
    <groupId>org.javers</groupId>
    <artifactId>javers-core</artifactId>
    <version>3.6.3</version>
</dependency>

If you’re going to use JaVers as an object diff tool, this is the only dependency you need.

javers-repository

If you are going to use JaVers as a data audit framework, choose the proper repository implementation. For example, if you’re using MongoDB add:

Gradle:

compile 'org.javers:javers-persistence-mongo:3.6.3'

Maven:

<dependency>
    <groupId>org.javers</groupId>
    <artifactId>javers-persistence-mongo</artifactId>
    <version>3.6.3</version>
</dependency>

Java 7 compatibility

Since 3.0, JaVers is written in Java 8. If you still use Java 7, you can’t use the latest version.

The last JaVers’ version compatible with Java 7 is 2.9.2.

Create a JaVers instance

Use JaversBuilder to create a JaVers instance:

import org.javers.core.Javers;
import org.javers.core.JaversBuilder;
//...
Javers javers = JaversBuilder.javers().build();

Now, the JaVers instance is up and ready, configured with reasonable defaults. Good enough to start.

Later on, you would probably need to refine the configuration and introduce some basic facts about your domain model to JaVers.

Object diff

Use the compare() method to calculate a diff for two arbitrary complex domain objects:

Person tommyOld = new Person("tommy", "Tommy Smart");
Person tommyNew = new Person("tommy", "Tommy C. Smart");

Diff diff = javers.compare(tommyOld, tommyNew);

See more diff examples.

Object audit

Use the commit() method to persist changes done on domain objects in JaversRepository:

Person robert = new Person("bob", "Robert Martin");
javers.commit("user", robert);

See more audit examples.