Dmitry Spikhalskiy created MNG-8480:
---------------------------------------
Summary: forceLegacyJavacApi=true omits important warning logs
Key: MNG-8480
URL: https://issues.apache.org/jira/browse/MNG-8480
Project: Maven
Issue Type: Bug
Components: Errors
Affects Versions: 3.8.8
Environment: Apache Maven 3.8.8
maven-compiler-plugin:3.13.0
JDK 21.0.5
Reporter: Dmitry Spikhalskiy
Specifying forceLegacyJavacApi=true omits important warning logs that may lead
to tricky to-investigate states.
Our project uses log4j2 that recently got OSGI-related refinements:
[https://logging.apache.org/log4j/2.x/release-notes.html#release-notes-2-22-0]
Our maven-compiler-plugin is configured as follows:
```
<configuration>
<forceLegacyJavacApi>true</forceLegacyJavacApi>
<showWarnings>true</showWarnings>
<failOnWarning>true</failOnWarning>
<compilerArgs>
<!-- compiling linter -->
<arg>-Xlint:all</arg>
</compilerArgs>
</configuration>
```
After log4j2 upgrade, the project compilation fails with no helpful diagnostic:
```
[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:
```
[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
```
<dependency>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bnd.annotation</artifactId>
<version>7.1.0</version>
<scope>compile</scope>
</dependency>
```
Expected behavior:
```<forceLegacyJavacApi>true</forceLegacyJavacApi>```
shouldn't lead to omitting important information needed to investigate the
compilation failure.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)