logging-log4j2 icon indicating copy to clipboard operation
logging-log4j2 copied to clipboard

Generate `Log4jPlugins` class does not compile in JPMS

Open ppkarwasz opened this issue 1 year ago • 7 comments

Currently log4j-plugin-processor in version 3.0.0-beta3 of Log4j Core adds BND annotations to the generated code.

While these might be useful for OSGi users, they cause a compilation error if the biz.aQute.bnd.annotation module is not present:

  • On the compiler classpath,
  • A static dependency on the module is not declared in the module-info.java file.

ppkarwasz avatar Nov 28 '24 16:11 ppkarwasz

A workaround for this issue is to add:

<dependency>
  <groupId>biz.aQute.bnd</groupId>
  <artifactId>biz.aQute.bnd.annotation</artifactId>
  <version>7.1.0</version>
  <scope>provided</scope>
</dependency>

to the compile-time only classpath and a:

requires static biz.aQute.bnd.annotation;

to the module descriptor. The annotations have a CLASS retention, so they don't cause problems at runtime.

ppkarwasz avatar Nov 28 '24 16:11 ppkarwasz

A workaround for this issue is to add:

biz.aQute.bnd biz.aQute.bnd.annotation 7.1.0 provided to the compile-time only classpath and a:

requires static biz.aQute.bnd.annotation; to the module descriptor. The annotations have a CLASS retention, so they don't cause problems at runtime.

Just wanted to confirm -- the suggested workaround code changes on the source -- not during usage, correct? Meaning... wait until beta4 to use the PlugProcessor in non-OSGi environments

lockhartja avatar Jan 16 '25 20:01 lockhartja

biz.aQute.bnd.annotation has a retention of CLASS, i.e. its presence or absence does not make a difference at runtime.

ppkarwasz avatar Jan 16 '25 20:01 ppkarwasz

@ppkarwasz to clarify my use case -- I was attempting to build a a custom plug however the annotation processor (using Kotlin Kapt) breaks -- complaining that the annotations are unable to be resolved. And tasks for the prompt feedback

error: cannot find symbol
@ServiceProvider(value = PluginService.class, resolution = Resolution.OPTIONAL)
                                                           ^
  symbol: variable Resolution

error: package aQute.bnd.annotation.spi does not exist
import aQute.bnd.annotation.spi.ServiceProvider;

error: cannot find symbol
@ServiceProvider(value = PluginService.class, resolution = Resolution.OPTIONAL)
 ^
  symbol: class ServiceProvider

lockhartja avatar Jan 16 '25 22:01 lockhartja

@lockhartja,

Did you try adding:

compileOnly 'biz.aQute.bnd:biz.aQute.bnd.annotation:7.1.0'

to your dependencies?

ppkarwasz avatar Jan 17 '25 12:01 ppkarwasz

Yes -- that does solve the issue -- thanks

lockhartja avatar Jan 19 '25 03:01 lockhartja

@ppkarwasz Maybe it is better to change milestone to 3.x?

Stefman87 avatar Feb 23 '25 20:02 Stefman87