Examples

Dependencies

Add the following dependencies:

<dependency>
  <groupId>io.ebean</groupId>
  <artifactId>ebean</artifactId>
  <version>13.6.5</version>
</dependency>

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

ebean-test

ebean-test should be added as a test dependency. This configures Ebean for running tests including automatic use of docker containers for Postgres, MySql, Oracle, SqlServer, Hana + support for H2 and SqlLite.

Refer to: docs / testing

build / plugins

In the build / plugins section:

  1. Add the tiles-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>
       <groupId>io.repaint.maven</groupId>
       <artifactId>tiles-maven-plugin</artifactId>
       <version>2.22</version>
       <extensions>true</extensions>
       <configuration>
         <tiles>
          <!-- other tiles ... -->
          <tile>io.ebean.tile:enhancement:13.6.5</tile>
        </tiles>
      </configuration>
    </plugin>


    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.10.1</version>
      <configuration>
        ...
        <annotationProcessorPaths>
           <path>
              <groupId>io.ebean</groupId>
              <artifactId>querybean-generator</artifactId>
              <version>13.6.5</version>
          </path>
          <!-- other annotation processors -->
        </annotationProcessorPaths>
      </configuration>
    </plugin>


  </plugins>
</build>

Maven enhancement tile

The maven tile above will enhance the code at build time for both src/main and src/test. This is simpler than defining the plugin in the traditional (non-tile) fashion and is the preferred approach.

If you want to specify the maven enhancement plugin in 'normal' non-tile fashion see maven plugin.

APT - querybean generation

Note that if there are no other annotation processors (e.g. mapstruct) then instead of explicitly registering the querybean-generator with the maven-compiler-plugin we can instead just add it as a dependency with provided scope.

JDBC Driver(s)

Add the dependency for the JDBC Driver(s) you want to use.

Kotlin KAPT

When using Kotlin we need to use KAPT (Kotlin annotation processing) to generate Kotlin query beans.

The recommended way to do this is via the io.avaje.kapt maven tiles as this makes it easier to add additional annotation processors (like DInject for dependency injection for example).

Add the maven tiles plugin into the build / plugins section of the pom.xml with the tiles for:

<plugin>
  <groupId>io.repaint.maven</groupId>
  <artifactId>tiles-maven-plugin</artifactId>
  <version>2.22</version>
  <extensions>true</extensions>
  <configuration>
    <tiles>
      <tile>io.ebean.tile:enhancement:13.6.5</tile> <!-- ebean enhancement -->

      <!-- Kotlin + Java compilers with KAPT support -->
      <tile>io.avaje.kapt:compile:1.1</tile>

      <!-- KAPT query bean generator -->
      <tile>io.avaje.kapt:querybean-generator:1.1</tile>

      <!-- other annotation processors ... -->
      <!-- <tile>io.avaje.kapt:dinject-generator:1.1</tile> -->
      <!-- <tile>io.avaje.kapt:javalin-generator:1.1</tile> -->

      <!-- other tiles ... -->

    </tiles>
  </configuration>
</plugin>

We can add other additional annotation processors by adding tiles, for example:

  • io.avaje.kapt:dinject-generator:1.1 - for DInject Dependency injection generation
  • io.avaje.kapt:javalin-generator:1.1 - for Javalin controller generation

Example project

Full example pom for Kotlin query bean generation