= Help/Usage section

This section describes usage error and how to fix them.

== Annotation Processing Tool

=== Router Not Found

*Exception*:

----
Route not found: `...`. Make sure Jooby annotation processor is configured properly.
----

The cause of this error is generated when you try to use a MVC route and the annotation processing 
tool is not configured properly.

*Maven Solution*:

Java build needs the `jooby-apt` dependency as https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#annotationProcessorPaths[annotationProcessorPaths].

Kotlin build also requires it via https://kotlinlang.org/docs/reference/kapt.html#using-in-maven[kapt].

.Java
[source, xml, role = "primary", subs="verbatim,attributes"]
----
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>{mavenCompilerPluginVersion}</version>
        <configuration>
          <annotationProcessorPaths>
            <path>
              <groupId>io.jooby</groupId>
              <artifactId>jooby-apt</artifactId>
              <version>{joobyVersion}</version>
            </path>
          </annotationProcessorPaths>
        </configuration>
      </plugin>
    </plugins>
  </build>
----

.Kotlin
[source, xml, role = "secondary", subs="verbatim,attributes"]
----
  <build>
    <plugins>
      <plugin>
        <artifactId>kotlin-maven-plugin</artifactId>
        <groupId>org.jetbrains.kotlin</groupId>
        <version>{kotlinVersion}</version>
        <configuration>
          <args>
            <arg>-java-parameters</arg>
          </args>
          <jvmTarget>${maven.compiler.target}</jvmTarget>
        </configuration>
        <executions>
          <execution>
            <id>kapt</id>
            <goals>
              <goal>kapt</goal>
            </goals>
            <configuration>
              <sourceDirs>
                <sourceDir>src/main/kotlin</sourceDir>
              </sourceDirs>
              <annotationProcessorPaths>
                <annotationProcessorPath>
                  <groupId>io.jooby</groupId>
                  <artifactId>jooby-apt</artifactId>
                  <version>{joobyVersion}</version>
                </annotationProcessorPath>
              </annotationProcessorPaths>
            </configuration>
          </execution>
          <execution>
            <id>compile</id>
            <goals>
              <goal>compile</goal>
            </goals>
            <configuration>
              <sourceDirs>
                <sourceDir>src/main/kotlin</sourceDir>
              </sourceDirs>
            </configuration>
          </execution>
          <execution>
            <id>test-kapt</id>
            <goals>
              <goal>test-kapt</goal>
            </goals>
            <configuration>
              <sourceDirs>
                <sourceDir>src/test/kotlin</sourceDir>
              </sourceDirs>
              <annotationProcessorPaths>
                <annotationProcessorPath>
                  <groupId>io.jooby</groupId>
                  <artifactId>jooby-apt</artifactId>
                  <version>{joobyVersion}</version>
                </annotationProcessorPath>
              </annotationProcessorPaths>
            </configuration>
          </execution>
          <execution>
            <id>test-compile</id>
            <goals>
              <goal>test-compile</goal>
            </goals>
            <configuration>
              <sourceDirs>
                <sourceDir>src/test/kotlin</sourceDir>
              </sourceDirs>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
----

*Gradle Solution*:

Java build needs an annotationProcessor statement using `jooby-apt`.

Kotlin builds needs a https://kotlinlang.org/docs/reference/kapt.html#using-in-gradle[kapt] dependency and statement using `jooby-apt`.

.Java
[source, groovy, role="primary", subs="verbatim,attributes"]
----
dependencies {
  annotationProcessor "io.jooby:jooby-apt:{joobyVersion}"
}
----

.Kotlin
[source, groovy, role="secondary", subs="verbatim,attributes"]
----
buildscript {
  ...
  dependencies {
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:{kotlinVersion}"
  }
}

...

apply plugin: "org.jetbrains.kotlin.kapt"

...

dependencies {
  kapt "io.jooby:jooby-apt:{joobyVersion}"
}
...
----

*IntelliJ Solution*

You need to enable IntelliJ annotation processing tool. Please checkout the https://www.jetbrains.com/help/idea/annotation-processors-support.html[IntelliJ documentation] to learn how to do it.

Please note that Kapt is still not supported for IntelliJ IDEA’s own build system. A simply workaround
is to configure Intellij to run Maven/Gradle compilation as a build step before running your tests 
or application class:

- Go to *Run > Edit Configurations ...*
- Select the application/test class run configuration
- Find the *Before build / Build* section
  - Select Add (plus button)
  - Select *Run Maven Goal* or *Run Gradle task*
    - For Maven type `compile` or `testCompile`
    - For Gradle type `classes` or `testClasses`

Now whenever you run tests or the application Mvc classes will be generated at compilation time.

Alternatively, you can delegate IntelliJ build/run actions to Maven or Gradle completely:

- https://www.jetbrains.com/help/idea/delegate-build-and-run-actions-to-maven.html

*Eclipse 4.9+*

You need https://www.eclipse.org/m2e/[M2Eclipse] for Maven or https://projects.eclipse.org/projects/tools.buildship[Gradle Buildship]

== Bean Converter

=== Parameter Name Missing

*Exception*:

----
Unable to provision parameter at position: '...', require by: ... Parameter's name is missing
----

Thrown when the bean converter has no access to a parameter name at runtime. Compilation must be 
done using `parameters` compiler option.

*Maven Solution*

.Java
[source, xml, role = "primary", subs="verbatim,attributes"]
----
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>{mavenCompilerPluginVersion}</version>
        <configuration>
        ...
          <compilerArgs>
            <arg>-parameters</arg>
          </compilerArgs>
        </configuration>
      </plugin>
    </plugins>
  </build>
----

.Kotlin
[source, xml, role = "secondary", subs="verbatim,attributes"]
----
  <build>
    <plugins>
      <plugin>
          <artifactId>kotlin-maven-plugin</artifactId>
          <groupId>org.jetbrains.kotlin</groupId>
          <version>{kotlinVersion}</version>
          <configuration>
            ...
            <args>
              <arg>-java-parameters</arg>
            </args>
            <jvmTarget>17</jvmTarget>
            ...
          </configuration>
        </plugin>
    </plugins>
  </build>
----

*Gradle Solution*

.Java
[source, groovy, role = "primary", subs="verbatim,attributes"]
----
tasks.withType(JavaCompile) {
  options.compilerArgs << '-parameters'
  options.debug = true
}
----

.Kotlin
[source, groovy, role = "secondary", subs="verbatim,attributes"]
----
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
  kotlinOptions.javaParameters = true
}
----
