Skip to content

Gradle: unexpected compiler warning with Log4j 2.25.3 #4007

@ppkarwasz

Description

@ppkarwasz

This issue is a continuation of the long-running -Werror -Xlint:all saga.

When all of the following apply:

  • the build uses Gradle,
  • the compiler is JDK 8 through 16,
  • compilation is run with -Werror -Xlint:all,
  • the code references a Log4j API class annotated with a biz.aQute.bnd.annotation
    (for example PropertiesUtil),

the build fails with a compiler warning promoted to an error.

The failure is caused by a bytecode-level mismatch: Log4j 2.25.3 exposes biz.aQute.bnd.annotation:7.1.0 via Gradle Module Metadata, but that artifact is built for Java 17 (class file version 61) and is therefore incompatible with JDK 8/11 compilers when -Xlint:classfile is enabled.

Example failure:

> Task :compileJava FAILED
.../log4j-api-2.25.3.jar(org/apache/logging/log4j/util/ProviderUtil.class): warning:
Cannot find annotation method 'value()' in type 'aQute.bnd.annotation.spi.ServiceConsumer':
bad class file:
.../biz.aQute.bnd.annotation-7.1.0.jar(aQute/bnd/annotation/spi/ServiceConsumer.class)
    class has wrong version 61.0, should be 52.0
    Please remove or make sure it appears in the correct subdirectory of the classpath.

Workarounds

Several workarounds are available:

  1. Use a newer JDK to compile the project.
    Even recent JDKs (including JDK 25) can still target Java 8 bytecode via --release. The JDK used for compilation does not dictate the output bytecode level.

  2. Disable the classfile lint category by adding -Xlint:-classfile.
    This category rarely provides actionable information and is the root cause of the failure here. See
    Upgrading to 2.24.1 produces a compile time warning: BaselineIgnore not found #3110 (comment) for additional context.

  3. Force a compatible annotation version by adding
    biz.aQute.bnd.annotation:6.4.1 to the application’s compileOnly configuration and enforcing that version in Gradle resolution.

Planned fix

This will be addressed in a future Log4j API release by downgrading the exported biz.aQute.bnd.annotation version to 6.4.1 in the Gradle Module Metadata (via the Gradle Module Metadata Maven Plugin), ensuring compatibility with Java 8 and Java 11 consumers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIncorrect, unexpected, or unintended behavior of existing codebuildAffects the build system or other automationgood first issueIssues that are good for contributors looking to get started

    Type

    Projects

    Status

    Ready

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions