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')
}

Dependencies

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

dependencies {
  ...
  compile('io.dinject:dinject:1.11')
  compile('io.dinject:dinject-controller:1.11')

  annotationProcessor('io.dinject:dinject-generator:1.11')
  annotationProcessor('io.dinject:javalin-generator:1.11')
  ...
}

Kotlin KAPT

See example at: https://github.com/dinject/examples/blob/master/basic-di-kotlin-maven/pom.xml

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

dependencies {
  ...
  kapt('io.dinject:dinject-generator:1.11')
  kapt('io.dinject:javalin-generator:1.11')
  ...
}

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.