Jonas_Astley
Jonas_Astley

Reputation: 161

There's Lombok annotation @Slf4j which won't work

I need your help. I have a problem with Lombock annotation @Slf4j. When I try to use it I don't have ability to use its functionality: enter image description here

There's my build.gradle file: enter image description here

I've already installed Lombock into my IntelliJ Idea and enabled Annotating processing, but it haven't got me resul yet. Can you make some advice? I would be very grateful!

Upvotes: 4

Views: 4039

Answers (2)

rzwitserloot
rzwitserloot

Reputation: 102842

Taking a wild stab here, but lombok doesn't include slf4j. It really can't do that1. All features in the extern packages work like this, and it is why the lombok.extern package layer exists: To show you that it's a lombok feature that makes some non-core ('external') dependency work nicer, not that the lombok feature includes this dependency or replaces it.

Thus, all you would need to fix this is to add slf4j to your dependencies:

compile 'org.slf4j:slf4j:1.7.31'

omr something along those lines. Note that SLF4j also needs runtime configuration (slf4j itself is just a 'frontend' that lets you write log statements that go to whereever your configuration says they go at runtime. This 'configuration' includes the code to actually do stuff with these logs. Slf4j tutorials will cover all this.

[1] Adding the deps automatically is not really possible; lombok ships with a number of features that are specifically to make some library / framework easier to use, we (DISCLAIMER: I do quite a bit of work on lombok) can't ship them all of those as deps of lombok, and we haven't (and probably would never) try to hack into your build system to make some sort of semi-dependent system where we detect you use e.g. @Slf4j and somehow make your build system include it only then.

Upvotes: 5

Paul Verest
Paul Verest

Reputation: 63912

There is some IDE build issue you have.

Why don't you adopt Maven (or Gradle) build tool, that is used in maybe 80% (gradle is maybe other 19.99%) team projects.

And then there is nothing specific about using Lombock https://projectlombok.org/setup/maven

just

<dependencies>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.20</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

And it works in any IDEA or most IDE

P.S. Specifically no configuration/plugin in IDEA since v2020.3 https://projectlombok.org/setup/intellij

P.P.S. If you use maven/gradle and have any issues in any IDE, try first to make sure, that there is no issues with build itself by running in command line

mvn package

or

gradle build

And then if build is OK, try to resolve specific IDE issue. Think like "what most people do or won't do to make it work"

For example you can install one more the newest IDEA instance, e.g. IDEA CE (that it undervalued, as it is free) and open your project there: it should just work without any dancing.

Upvotes: -1

Related Questions