I’m trying to use Lombok in my project that I’m developing using IntelliJ IDEA 11.
I’ve installed 3rd-party plugin for IDEA and it seems working fine because IDEA sees all autogenerated methods/fields.
So I have a class that uses Slf4j. I annotated it like this
import lombok.extern.slf4j.Slf4j; @Slf4j public class TestClass { public TestClass() { log.info("Hello!"); } }
But when I build my project compiler spits: cannot find symbol variable log
.
Could you please tell me what I’m missing here?
Update: It turned out it’s RequestFactory annotation process that fails.
input files: {com.zasutki.courierApp.server.TestServlet, com.mine.courierApp.server.model.DatastoreObject} annotations: [javax.inject.Singleton, javax.inject.Inject, lombok.Getter, lombok.Setter, com.googlecode.objectify.annotation.Id, com.googlecode.objectify.annotation.OnSave] Processor com.google.web.bindery.requestfactory.apt.RfValidator matches [lombok.Getter, com.googlecode.objectify.annotation.Id, javax.inject.Inject, lombok.Setter, com.googlecode.objectify.annotation.OnSave, javax.inject.Singleton] and returns false. cannot find symbol variable log
Any ideas on workarounds?
Update2: Perhaps it’s not something readers want to hear but I ended up switching to Scala.
Advertisement
Answer
I have fixed it in IDEA 12 by setting check box Enable annotation processing
in:
Settings -> Compiler -> Annotation Processors
For IDEA 2016.2:
Preferences… > Build, Execution, Deployment > Compiler > Annotation Processors
After enabling, run Build -> Rebuild Project to have annotations recognized and eliminate errors.
For IDEA 2019.2.1, depending on how the project is configured, installing the Project Lombok plugin may not be sufficient. Here is another way to use Project Lombok with IntelliJ IDEA:
- Visit https://projectlombok.org/download
- Download the JAR file into the project lib directory (e.g.,
$HOME/dev/java/project/libs
). - Start the IDE.
- Click File 🠖 Settings.
- Expand Build, Execution, Deployment 🠖 Compiler 🠖 Annotation Processors.
- Ensure Enable annotation processing is checked.
- Ensure Store generates sources relative to is selected based on the project’s module settings (if Module output directory doesn’t work, come back and try the other setting).
- Click Apply.
- Click Plugins.
- Click Marketplace.
- Set search field to:
lombok
- Install Lombok.
- Click OK.
- Restart the IDE if prompted.
- Click File 🠖 Project Structure.
- Select Libraries.
- Click the + symbol to add a new project library (or press Alt+Insert).
- Select Java.
- Set the path to:
$HOME/dev/java/project/libs/lombok.jar
- Click OK.
- Select the modules to apply.
- Click OK.
- Optionally, rename
lombok
toProject Lombok 1.18.8
. - Click OK.
The project can now import from the lombok
package and use Project Lombok annotations (e.g., lombok.Setter
and lombok.Getter
).