JaVers needs funding to sustain. You can sponsor JaVers development easily via GitHub Sponsors or Open Collective.

Getting started

All JaVers artifacts are published to Maven Central.

Spring Boot Starter

The easiest and recommended way to start with Javers is adding one of our Spring Boot starters to your project dependencies.

If you are using MongoDB — take:

compile 'org.javers:javers-spring-boot-starter-mongo:5.13.0'

If you are using an SQL database:

compile 'org.javers:javers-spring-boot-starter-sql:5.13.0'

These starters provide default configuration and create the Javers instance as a Spring bean. You can start using Javers with almost no configuration.

Read more about Javers’ Spring Boot integration and Javers’ Spring integration.

Javers tutorial on baeldung.com

Recently, Eugen Baeldung has written an excellent tutorial — Using JaVers for Data Model Auditing in Spring Data

We recommend reading it in the first place.

Vanilla Javers

If you are not using Spring, add javers-core to your project dependencies and (optionally) choose proper javers-repository module.

javers-core

Gradle:

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

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:5.13.0'

If you are using an SQL database — add:

compile 'org.javers:javers-persistence-sql:5.13.0'

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 javers.commit() method to audit changes done on your domain objects. Javers saves subsequent versions of domain objects as Snapshots in JaversRepository

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

See more audit examples.

Auto audit

In order to automatically audit objects saved to Spring Data repositories use the @JaversSpringDataAuditable annotation:

@JaversSpringDataAuditable
public interface PersonRepository extends CrudRepository<Person, String> {
}

Read more about the Auto audit aspects.