IntelliJ IDEA 2016.3 Help

Enabling Annotations

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 /help/img/idea/2016.3/projectStructure.png to open the project structure dialog.
  2. In the Project Structure dialog box, click Libraries.
  3. Click /help/img/idea/2016.3/new.png. Select Library Files dialog box opens.
  4. Under <IntelliJ IDEA home> directory, select redist/annotation.jar/ redist/annotation-java8.jar, and click OK:
    /help/img/idea/2016.3/add_annotations.png
  5. If your project contains more than one module, choose the desired module to be modified, and click OK:
    /help/img/idea/2016.3/choose_module1.png
  6. The new library is added to the classpath:
    /help/img/idea/2016.3/add_annotations1.png

Enabling annotations in Gradle or Maven projects

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

  1. Click /help/img/idea/2016.3/projectStructure.png 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 /help/img/idea/2016.3/new.png 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.
    /help/img/idea/2016.3/annotations_select_library_type.png
  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.
    /help/img/idea/2016.3/annotations_download_from_maven_repository.png
  6. In the Choose Libraries dialog box, click Add Selected.
    /help/img/idea/2016.3/annotations_choose_libraries.png

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

    /help/img/idea/2016.3/annotations_added_dependency.png

Enabling annotations using editor

To enable annotations in the editor:

  • In the editor, write @NotNull and press Alt+Enter:
    /help/img/idea/2016.3/annotations_NotNull.png

The selected JAR file is added:

/help/img/idea/2016.3/annotations_NotNull_result.png

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: 7 December 2016