Home  >  Article  >  Java  >  Why Can't I Use Lombok's @Slf4j in IntelliJ IDEA?

Why Can't I Use Lombok's @Slf4j in IntelliJ IDEA?

Patricia Arquette
Patricia ArquetteOriginal
2024-11-15 12:01:02316browse

Why Can't I Use Lombok's @Slf4j in IntelliJ IDEA?

Lombok Compilation Issues in IntelliJ IDEA

Problem Description:

While using Lombok in an IntelliJ IDEA project, the user encounters a "cannot find symbol" error for the log variable in an annotated class. Despite installing the Lombok plugin and observing the successful recognition of Lombok-generated methods and fields within the IDE, compilation fails.

Solution (for IntelliJ IDEA 12):

To resolve this issue in IntelliJ IDEA 12, enable the "Enable annotation processing" option under "Settings -> Compiler -> Annotation Processors". After this, rebuild the project for the IDE to recognize annotations and eliminate compilation errors.

Solution (for IntelliJ IDEA 2016.2):

For IntelliJ IDEA 2016.2, the following steps should be followed:

  1. Navigate to "Preferences... -> Build, Execution, Deployment -> Compiler -> Annotation Processors".
  2. Ensure the "Enable annotation processing" checkbox is selected.

Alternative Solution (for IntelliJ IDEA 2019.2.1):

  1. Download the latest Lombok JAR file from https://projectlombok.org/download.
  2. Add the JAR file to the project's lib directory.
  3. In IntelliJ IDEA, enable "Enable annotation processing" under "File -> Settings -> Build, Execution, Deployment -> Compiler -> Annotation Processors".
  4. Set "Store generates sources relative to" based on the project's module settings.
  5. Install the Lombok plugin from the IntelliJ IDEA Marketplace.
  6. Add the Lombok JAR file as a project library.

By following these steps, the project will be able to import from the Lombok package and use Lombok annotations, resolving the compilation errors related to the log variable.

The above is the detailed content of Why Can't I Use Lombok's @Slf4j in IntelliJ IDEA?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn