I'm facing an issue with Lombok in my multimodule maven project. I have two classes :
@Slf4j
public class Parent {}
@Slf4j
public class Child extends Parent {
public void m() {
log.debug("hello");
}
}
There is also a parent maven project in which the lombok dependency is defined. And a child maven project in which I define the parent project as maven parent.
When I use generated log instance in Child class, compilation error occurs :
[ERROR] log has private access in <Child class>
I could resolved the issue in two ways:
Why so? Any workaround / best way to define the lombok dependency ?
Thanks for your help.
Using :
Inheritance should not impact your issue in any way. When you use @Slf4j annotation Lombok creates private static final field and static fields are not inherited. In your case generated code looks like this:
public class Parent {
private static final Logger log = LoggerFactory.getLogger(Parent.class);
public Parent() {}
}
public class Child extends Parent {
private static final Logger log = LoggerFactory.getLogger(Child.class);
public Child() {}
public void m() {
log.debug("hello");
}
}
With multi-module maven project you need to ensure that inter-module dependencies are specified correctly. If lombok is on the classpath everything should work perfectly fine out of the box.
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