@Slf4j picking up wrong slf4j interface

I have a gradle app that includes the following:

implementation 'ch.qos.logback:logback-classic'
implementation 'ch.qos.logback.contrib:logback-json-classic:0.1.5'
implementation 'ch.qos.logback.contrib:logback-jackson:0.1.5'
...
implementation 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

in my classes I have:

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ...

However, when ctrl + clicking any log.xxx statement, it takes me to a slf4j that is part of another library I have, instead of the main lombok one, I have no idea why since the import is from lombok. Other modules that do not have this library go to lombok > slf4j as expected.

It works, but is there a way to force it somehow?


Solution 1:

Lombok does not include Slf4j, nor does it have a dependency on it.

You have to provide your own.

If you add @Slf4j, lombok will generate code that relies on the compile-time and runtime availability of some slf4j-api version, that you have to provide yourself.

If you ctrl-click on warn in log.warn("foo"), your IDE will take you to the warn method in your provided dependency, typically in slf4j-api-<version>.jar. If you click on the log part, it should take you to the @Slf4j annotation at the top of your class.

Disclaimer: I am a Project Lombok maintainer.