Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Log4jPlugins class does not compile in JPMS #3251

Open
ppkarwasz opened this issue Nov 28, 2024 · 6 comments
Open

Generate Log4jPlugins class does not compile in JPMS #3251

ppkarwasz opened this issue Nov 28, 2024 · 6 comments

Comments

@ppkarwasz
Copy link
Contributor

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
Copy link
Contributor Author

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 ppkarwasz added this to the 3.0.0-beta4 milestone Nov 28, 2024
ppkarwasz added a commit that referenced this issue Nov 30, 2024
This adds a `log4j.plugin.enableBndAnnotations` option to the `PluginProcessor`. Its default value is inferred from the compiler classpath.

We also rename the `pluginPackage` option to a more coherent `log4j.plugin.package` option.

Closes #3251
@lockhartja
Copy link

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

@ppkarwasz
Copy link
Contributor Author

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

@lockhartja
Copy link

lockhartja commented Jan 16, 2025

@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

@ppkarwasz
Copy link
Contributor Author

ppkarwasz commented Jan 17, 2025

@lockhartja,

Did you try adding:

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

to your dependencies?

@ppkarwasz ppkarwasz added waiting-for-user More information is needed from the user and removed waiting-for-maintainer labels Jan 17, 2025
@lockhartja
Copy link

Yes -- that does solve the issue -- thanks

@github-actions github-actions bot added waiting-for-maintainer and removed waiting-for-user More information is needed from the user labels Jan 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants