IntelliJ IDEA 2017.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. Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S).
  2. In the Project Structure dialog box, click Libraries.
  3. Click new. 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 new 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:
    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.

Last modified: 6 March 2018