[MNG-8480] forceLegacyJavacApi=true omits important warning logs
- Dominant language
- Java
- Stars
- 5.3k
- Forks
- 3.1k
- Avg merge
- 21h 11m
- Merged PRs (30d)
- 312
Description
**[Dmitry Spikhalskiy](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=spikhalskiy)** opened **[MNG-8480](https://issues.apache.org/jira/browse/MNG-8480?redirect=false)** and commented
## Current behavior
Specifying forceLegacyJavacApi=true omits important warning logs that may lead to tricky to-investigate states.
## Expected behavior
\true\
shouldn't lead to omitting important information needed to investigate the compilation failure.
## Context
Our project uses log4j2 that [recently](https://logging.apache.org/log4j/2.x/release-notes.html#release-notes-2-22-0) got OSGI-related refinements ([relevant discussion](https://github.com/apache/logging-log4j2/issues/3110)).
Our maven-compiler-plugin is configured as follows:
```xml
true
true
true
false
-Xlint:all
```
After log4j2 upgrade, the project compilation fails with no helpful diagnostic:
```java
[INFO] — maven-compiler-plugin:3.13.0:compile (default-compile) @ ... —
[INFO] Recompiling the module because of changed dependency.
[INFO] Compiling 190 source files with javac [debug release 21] to target/classes
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for ...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19.421 s
[INFO] Finished at: 2025-01-02T17:41:59-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0:compile (default-compile) on project ...: Compilation failure -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
```
`-e` provides a stacktrace that doesn't lead to a rootcause.
To find the root cause, we need to disable forceLegacyJavacApi`. This provides the following output:
```java
[INFO] — maven-compiler-plugin:3.13.0:compile (default-compile) @ ... —
[INFO] Recompiling the module because of changed dependency.
[INFO] Compiling 190 source files with javac [debug release 21] to target/classes
[INFO] Annotation processing is enabled because one or more processors were found
on the class path. A future release of javac may disable annotation processing
unless at least one processor is specified by name (-processor), or a search
path is specified (--processor-path, --processor-module-path), or annotation
processing is enabled explicitly (-proc:only, -proc:full).
Use -Xlint:-options to suppress this message.
Use -proc:none to disable annotation processing.
[INFO] -------------------------------------------------------------
[WARNING] COMPILATION WARNING :
[INFO] -------------------------------------------------------------
[WARNING] Cannot find annotation method 'value()' in type 'aQute.bnd.annotation.baseline.BaselineIgnore': class file for aQute.bnd.annotation.baseline.BaselineIgnore not found
[WARNING] Cannot find annotation method 'value()' in type 'aQute.bnd.annotation.baseline.BaselineIgnore': class file for aQute.bnd.annotation.baseline.BaselineIgnore not found
[INFO] 2 warnings
[INFO] -------------------------------------------------------------
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] warnings found and -Werror specified
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for ...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 20.303 s
[INFO] Finished at: 2025-01-02T17:58:54-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0:compile (default-compile) on project ...: Compilation failure
[ERROR] warnings found and -Werror specified
```
That leads to a solution to the problem, which is adding
```xml
biz.aQute.bnd
biz.aQute.bnd.annotation
7.1.0
compile
```
---
**Affects:** 3.8.8
Contributor guide
Research direction
Start by tracing the maven-compiler-plugin handling of the forceLegacyJavacApi option and compare its output with the non-legacy path. Reproduce the failure using the configuration and compilerArgs shown in the issue, including -Xlint:all, showWarnings, and failOnWarning. Done means important javac warnings and the resulting diagnostic remain visible when forceLegacyJavacApi is true.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100