JDBC Driver(s)

Add the dependency for the JDBC Driver(s) you want to use. For example, with Postgres we could add:

<!-- JDBC Driver(s) -->
<dependency>
  <groupId>org.postgresql</groupId>
  <artifactId>postgresql</artifactId>
  <version>42.7.2</version>
</dependency>

Main dependency

Ebean provides a dependency per database platform. We include one or more of these dependencies for each database that our application is going to use.

  • io.ebean:ebean-clickhouse
  • io.ebean:ebean-cockroach
  • io.ebean:ebean-db2
  • io.ebean:ebean-hana
  • io.ebean:ebean-h2
  • io.ebean:ebean-mysql
  • io.ebean:ebean-mariadb
  • io.ebean:ebean-oracle
  • io.ebean:ebean-postgres
  • io.ebean:ebean-sqlanywhere
  • io.ebean:ebean-sqlite
  • io.ebean:ebean-sqlserver
  • io.ebean:ebean-yugabyte

For example, if our application is only going to use Postgres then we add the io.ebean:ebean-postgres dependency.

<dependency>
  <groupId>io.ebean</groupId>
  <artifactId>ebean-postgres</artifactId>
  <version>14.1.0</version>
</dependency>

If for example our application is going to use both YugabyteDB and ClickHouse then we add both dependencies.

<dependency>
  <groupId>io.ebean</groupId>
  <artifactId>ebean-yugabyte</artifactId>
  <version>14.1.0</version>
</dependency>
<dependency>
  <groupId>io.ebean</groupId>
  <artifactId>ebean-clickhouse</artifactId>
  <version>14.1.0</version>
</dependency>

If we want to support all platforms we can just use io.ebean:ebean which is a composite of all the supported platforms.

<dependency>
  <groupId>io.ebean</groupId>
  <artifactId>ebean</artifactId> <!-- All database platforms -->
  <version>14.1.0</version>
</dependency>

Test dependency - ebean-test

Add io.ebean:ebean-test as a test dependency.

This configures Ebean for running tests including automatic use of docker containers for Postgres, MySql, Oracle, SqlServer, ClickHouse, Yugabyte, Hana + support for H2 and SqlLite.

Refer to: docs / testing

<!-- Test dependencies -->
<dependency>
  <groupId>io.ebean</groupId>
  <artifactId>ebean-test</artifactId>
  <version>14.1.0</version>
  <scope>test</scope>
</dependency>

build / plugins

In the build / plugins section:

  1. Add the ebean-maven-plugin to perform build time enhancement
  2. Add or modify the maven-compiler-plugin to register the querybean-generator annotation processor.
<build>
  <plugins>

     <plugin> <!-- perform ebean enhancement -->
       <groupId>io.ebean</groupId>
       <artifactId>ebean-maven-plugin</artifactId>
       <version>14.1.0</version>
       <extensions>true</extensions>
     </plugin>

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.10.1</version>
      <configuration>
        <annotationProcessorPaths>
           <path> <!-- generate ebean query beans -->
              <groupId>io.ebean</groupId>
              <artifactId>querybean-generator</artifactId>
              <version>14.1.0</version>
          </path>
        </annotationProcessorPaths>
      </configuration>
    </plugin>

  </plugins>
</build>

Example pom for Postgres

An example pom for an application that only uses Postgres is:

<?xml version="1.0" encoding="UTF-8"?>
  <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>hello-ebean</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
      <maven.compiler.release>21</maven.compiler.release> <!-- Prefer release -->
      <maven.compiler.source>21</maven.compiler.source> <!-- fallback -->
      <maven.compiler.target>21</maven.compiler.target> <!-- fallback -->
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
      <dependency> <!-- JDBC Driver(s) -->
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>42.7.1</version>
      </dependency>

      <dependency> <!-- ebean postgres, add more platforms as needed -->
        <groupId>io.ebean</groupId>
        <artifactId>ebean-postgres</artifactId>
        <version>14.1.0</version>
      </dependency>

      <!-- test dependencies -->
      <dependency>
        <groupId>io.ebean</groupId>
        <artifactId>ebean-test</artifactId>
        <version>14.1.0</version>
        <scope>test</scope>
      </dependency>

      <dependency> <!-- Optional extra: JUnit5 + AssertJ + Mockito -->
        <groupId>io.avaje</groupId>
        <artifactId>junit</artifactId>
        <version>1.5</version>
        <scope>test</scope>
      </dependency>

    </dependencies>

    <build>
      <plugins>

        <plugin> <!-- perform ebean enhancement -->
          <groupId>io.ebean</groupId>
          <artifactId>ebean-maven-plugin</artifactId>
          <version>14.1.0</version>
          <extensions>true</extensions>
        </plugin>

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.10.1</version>
          <configuration>
            <annotationProcessorPaths>
               <path> <!-- generate ebean query beans -->
                  <groupId>io.ebean</groupId>
                  <artifactId>querybean-generator</artifactId>
                  <version>14.1.0</version>
              </path>
            </annotationProcessorPaths>
          </configuration>
        </plugin>

      </plugins>
    </build>
</project>