I have trouble with using Lombok's annotations, cause it seems like jar wasn't even imported to project:
import lombok.extern.slf4j.Slf4j;
/**
* Created by John on 2017-03-20.
*/
@Slf4j
public class App {
public static void main(String[] args)
{
log.info("Hello");
}
}
It says:
Cannot resolve method info(java.lang.String)
When compiling:
Error:(6, 1) java: package org.slf4j does not exist
I did:
I've looked for a solution here:
Still the same problem. Any advice would be appriciated.
UPDATE: pom.xml if it helps:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>example</groupId>
<artifactId>com</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.14</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
By adding the @Getter and @Setter annotations, we told Lombok to generate these for all the fields of the class. @NoArgsConstructor will lead to an empty constructor generation. Note that this is the whole class code, we're not omitting anything unlike the version above with the // getters and setters comment.
What is Lombok. Project Lombok (from now on, Lombok) is an annotation-based Java library that allows you to reduce boilerplate code. Lombok offers various annotations aimed at replacing Java code that is well known for being boilerplate, repetitive, or tedious to write.
You also need to add at least the slf4j-api dependency to your project.
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
Disclosure: I am a Lombok developer.
You need to:
Enable annotation processing in Intellij: Preferences -> Build,Execution,Deployment -> Compiler -> Annotation Processors -> Enable Annotation processing.
Restart Intellij.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With