Getting started with Gradle

See the example at: examples/javalin-gradle-java-basic/build.gradle

Gradle 5.2+

Use Gradle version 5.2 or greater which has better support for annotation processing.

Also review the IntelliJ IDEA Gradle settings - see below.

Optional: OpenAPI plugin

Optionally add the io.dinject.openapi plugin to have the openapi.json (swagger) to be generated into src/main/resources/public.

plugins {
  id('io.dinject.openapi') version('1.2')


Add dinject and dinject-controller as compile dependencies.
Add dinject-generator and javalin-generator as annotation processors.

dependencies {


Kotlin KAPT

See example at:

For use with Kotlin we change the annotationProcessor to be kapt for the Kotlin compiler.

dependencies {

OpenAPI Plugin configuration

We can change the location of the generated openapi file by adding an openapi configuration section in build.gradle.

openapi {
  destination = 'other/my-api.json'

IntelliJ IDEA with Gradle

We want to delegate the build to Gradle (to properly include the annotation processing) so check our IDEA settings.

Settings / Build / Compiler / Annotation processors

Ensure that Enable annotation processing is disabled so that the build is delegated to Gradle (including the annotation processing):

Settings / Build / Build tools / Gradle

Make sure Build and run is delegated to Gradle.

Optionally set Run tests using to Gradle but leaving it to IntelliJ IDEA should be ok.