Related: Trouble Shooting

Query bean generation with Gradle

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()

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

Add ebean-querybean dependency

dependencies {
  compile 'io.ebean:ebean-querybean:11.36.1'


Java APT build.gradle

Add the idea plugin if required.

apply plugin: 'idea'

Add the configurations apt section if required.

configurations {

Add an idea module section to tell IntelliJ Idea about the generated query beans.

idea {
  module {
    sourceDirs += file("$projectDir/generated")
    generatedSourceDirs += file("$projectDir/generated")

Add querybeans = true to the ebean section

ebean {
  debugLevel = 0
  queryBeans = true
Example project

Full example build.gradle with apt query bean generation


Kotlin KAPT build.gradle

Add the plugins for org.jetbrains.kotlin.jvm and org.jetbrains.kotlin.kapt.

buildscript {
  repositories {
  dependencies {
    classpath "io.ebean:ebean-gradle-plugin:11.36.1"
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.11"

apply plugin: 'idea'
apply plugin: 'io.ebean'
apply plugin: "org.jetbrains.kotlin.jvm"
apply plugin: "org.jetbrains.kotlin.kapt"

Add kapt dependency for io.ebean:kotlin-querybean-generator.

dependencies {

  compile ...
  compile "io.ebean:ebean:11.36.1"
  compile "io.ebean:ebean-querybean:11.36.1"

  kapt "io.ebean:kotlin-querybean-generator:11.36.1"

  testCompile ...

Set jvmTarget to 1.8 for both compileKotlin and compileTestKotlin.

compileKotlin {
  kotlinOptions.jvmTarget = "1.8"

compileTestKotlin {
  kotlinOptions.jvmTarget = "1.8"
Example project

Full example build.gradle with kapt query bean generation

Note that unlike for Gradle Java we don't use ebean.queryBeans = true and nor do we need to specify idea.module.sourceDirs or idea.module.generatedSourceDirs



Edit Page