Related: Trouble Shooting

Query bean generation with Maven

We can optionally add a Java annotation processor (APT) to generate query beans. This allows us to write type safe queries like:

List<Customer> customers =
  new QCustomer()
  .name.startsWith("Rob")
  .findList();

Skip this if you don't want to use query beans.

Add ebean-querybean dependency

<dependency>
  <groupId>io.ebean</groupId>
  <artifactId>ebean-querybean</artifactId>
  <version>${version}</version>
</dependency>
<dependency org="io.ebean" name="ebean-querybean" rev="${version}"/>
@Grapes(
  @Grab(group='io.ebean', module='ebean-querybean', version='${version}')
)
'io.ebean:ebean-querybean:${version}'
'io.ebean:ebean-querybean:${version}'
libraryDependencies += "io.ebean" % "ebean-querybean" % "${version}"
[io.ebean/ebean-querybean "${version}"]

Java APT

To generate Java query beans with maven add provided scope dependency for querybean-generator

<!-- annotation processor to generate query beans -->
<dependency>
  <groupId>io.ebean</groupId>
  <artifactId>querybean-generator</artifactId>
  <version>11.32.1</version>
  <scope>provided</scope>
</dependency>
Example project

Full example pom with query bean generation

Kotlin KAPT

To generate Kotlin query ebeans add the kotlin-kapt maven tile.

This tile brings in the kotlin-maven-plugin with configuration for kotlin-querybean-generator annotation processor. As such remove the kotlin-maven-plugin that will already be in the pom.xml (as the tile will bring in one that is configured to run the annotation processor).

Add the maven tile into the build / plugins section of the pom.xml.

<plugin>
  <groupId>io.repaint.maven</groupId>
  <artifactId>tiles-maven-plugin</artifactId>
  <version>2.12</version>
  <extensions>true</extensions>
  <configuration>
    <tiles>
      <tile>io.ebean.tile:enhancement:7.4</tile> <!-- ebean enhancement -->
      <tile>io.ebean.tile:kotlin-kapt:1.5</tile> <!-- kotlin compile with query bean generation -->
      <!-- other tiles ... -->
    </tiles>
  </configuration>
</plugin>
Example project

Full example pom for Kotlin query bean generation

Edit Page