IntelliJ IDEA 2020.1 Help

Configure annotation processors

You can configure IntelliJ IDEA to process custom annotations during the compilation time. The process of generating code at compile time to handle the annotations is called Annotation Processing.

The annotation processor can validate, generate, and modify your code based on the annotations, which help you significantly reduce the amount of code you need to write. The annotation processor could be stored inside your project. In this case IntelliJ IDEA obtains it from the classpath. If the annotation processor is stored outside the project then you need to add a path of the annotation processor JAR manually.

When you add annotation processors through the build scripts in Maven or Gradle projects, IntelliJ IDEA automatically enables the annotation processing and adds the appropriate paths in the annotation processor settings.

Annotation processing profile

An annotation profile is a set of configuration options for annotation processing. The options include a location of the annotation processing output, specific annotation processors, and their parameters.

The default profile always exists. All the modules comprising a project use the default profile. You can create a new profile, group several modules under it and configure an annotation processing just for the specified group of modules.

Configure an annotation profile

  1. In the Settings/Preferences dialog Ctrl+Alt+S, go to Build, Execution, Deployment | Compiler | Annotation Processors.

  2. On the the Annotation Processors page, click the Add icon on the bottom of the page.

  3. In the Create new profile dialog, specify the profile name.
    Create the annotation processor profile

    To move a module to the created profile, select the module you need, click the Move icon (F6) and select the target profile.

Configure the annotation processing for a profile

  1. Select the desired annotation profile.

  2. Select Enable annotation processing and configure the following options:
    • Obtain processors from project classpath: leave this opiton enabled if you use a custom annotation processor as part of your project, or if the processor is stored in a .jar file attached to all the corresponding modules as a library.

    • Processor path: select this option and specify the path to the annotation processor if it is stored outside the project.

      In case of a Gradle project that has the annotationProcessor dependency specified in the build.gradle file, this field will contain a path to annotation processor used by Gradle when you import your Gradle project. When you build such project with Gradle, IntelliJ IDEA generates the appropriate subdirectories inside the build directory in the Project tool window.

      Project tool window: annotationProcessor

      In case of a Maven project, the field will contain a path to annotioan processor specified in pom.xml.

    • Use --processor-module-path compiler option (for java 9 and later): assume that the specified path is a module path: a path of JARs or directories containing packaged Java modules. In order to be discovered and run from the module path, an annotation processor should be packaged as a Java module and registered with the ServiceLoader in the module declaration.

    • Store generated sources relative to: use the Module output directory and Module content root options to define where the sources generated by the annotation processors are stored, and to override the default behaviour for a profile.

    • Production sources and Test sources: use these fields to specify the name of the directory where the annotation processor output will be stored. If the field is left blank, the files generated by the annotation processor will be stored under the project output directory. When the name is specified, the directory with this name will be created under the content root after automatic annotation processing.

    • Processor FQ Name: specify the fully qualified names of the processors to be launched. If nothing is specified, then IntelliJ IDEA will launch all the processors detected in the specified location.

    • Annotation processor options: use this area to configure processor run options either as -key=value, or key=value. Use spaces to separate individual options.

Last modified: 7 July 2020