IntelliJ IDEA 2016.2 Help

Enabling Annotations

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. Under that <IntelliJ IDEA home> directory, select redist/annotation .jar, and click OK:
    add_annotations
  4. Click add. Select Library Files dialog box opens.
  5. If your project contains more than one module, choose the desired module to be modified, and click OK:
    choose_module
  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 Alt +Enter to invoke Add 'annotations' to classpath action.
    annotations_NotNull

IntelliJ IDEA will automatically choose Java 5 or Java 8 compatible JAR file based on your project's settings and add the JAR file to the project.

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

Last modified: 5 September 2016