On this page:

Introduction

IntelliJ IDEA lets you enable annotations in projects locally, through Maven repository for projects imported from Gradle or Maven model and through the editor.

Enabling annotations in the project

To enable annotations, follow these steps:

  1. Click projectStructure to open the project structure dialog.
  2. In the Project Structure dialog box, click Libraries.
  3. Click add. Select Library Files dialog box opens.
  4. Under <IntelliJ IDEA home> directory, select redist/annotation.jar/ redist/annotation-java8.jar, and click OK:

    add_annotations

  5. If your project contains more than one module, choose the desired module to be modified, and click OK:

    choose_module1

  6. The new library is added to the classpath:

    add_annotations1

Enabling annotations in Gradle or Maven projects

To enable annotations in Gradle or Maven projects, follow these steps:

  1. Click projectStructure to open the project structure dialog.
  2. In the Project Structure dialog box, on the Modules page, click the Dependencies tab.
  3. On the Dependencies tab, click add and from the list that opens, select Library.
  4. In the Choose Library dialog, click New Library and from the Select Library Type list, select From Maven.

    annotations_select_library_type

  5. In the Download Library From Maven Repository dialog, enter org.jetbrains:annotations:15.0 that contains annotations for Java 8 or org.jetbrains:annotations-java5:15.0 that contains annotations compatible with Java 5 and click OK.

    annotations_download_from_maven_repository

  6. In the Choose Libraries dialog box, click Add Selected.

    annotations_choose_libraries

    The new library is added to the list of dependencies and to the classpath.

    annotations_added_dependency

Enabling annotations using editor

To enable annotations in the editor:

  • In the editor, write @NotNull and press ⌥⏎ or ⌥⏎⌥⏎ or ⌥⏎⌘1 or ⌘1⌥ Enter, ⌥⏎ or ⌥⏎⌥ Enter, ⌥⏎ or ⌥⏎:

    annotations_NotNull

The selected JAR file is added:

annotations_NotNull_result

Note that if a project is imported from the Maven model, IntelliJ IDEA will add the dependency to the pom.xml.

See Also

Procedures: