-
Enhancement
-
Resolution: Not an Issue
-
P3
-
None
-
18.0.2
-
None
An external report:
-------------------------
If you compile a project that has compiler warnings, javac's output indicates which Xlint option will suppress the warning. But when compiling the same code under maven-compiler-plugin, this vital information is suppressed so the user has a difficult time figuring out which option to use. Ideally the output should indicate which Xlint option corresponds to the warning.
Running mvn compile on the testcase results in:
[INFO] — maven-compiler-plugin:3.8.0:compile (default-compile) @ testcase —
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to C:\Users\Gili\Documents\3rdparty\testcase\target\classes
[WARNING] /C:/Users/Gili/Documents/3rdparty/testcase/src/main/java/module-info.java:[2,32] module not found: someOtherModule
Then running the following compilation:
javac -d C:\Users\Gili\Documents\3rdparty\testcase\target\classes -classpath C:\Users\Gili\Documents\3rdparty\testcase\target\classes; -sourcepath C:\Users\Gili\Documents\3rdparty\testcase\src\main\java;C:\Users\Gili\Documents\3rdparty\testcase\target\generated-sources\annotations; -s C:\Users\Gili\Documents\3rdparty\testcase\target\generated-sources\annotations -g -target 11 -source 11 -encoding UTF-8 com\company\SomeClass.java module-info.java
The following output is seen.
module-info.java:2: warning: [module] module not found: someOtherModule
exports com.company to someOtherModule;
^
1 warning
Notice that the javac output includes "[module]" at the beginning of the warning message. This indicates that "-Xlint:-module" will suppress this warning. I was expecting maven-plugin-compiler to show this information in its output.
As per maven-compiler-plugin team:
They use the result from compilation with this class https://docs.oracle.com/en/java/javase/17/docs/api/java.compiler/javax/tools/Diagnostic.html. In case of error/warning, they use the method diagnostic.getMessage(Locale.getDefault()) (
In this case the method returns module not found: someOtherModule but at the same time diagnostic.toString() is returning:
/Volumes/workspace/dev/sources/plexus/plexus-compiler/plexus-compiler-its/target/it/missing-warnings/src/main/java/module-info.java:2: warning: [module] module not found: someOtherModule
exports com.company to someOtherModule;
So suspecting this behavior as a JDK bug.
A reproducer code (Testcase.java) is also attached.
-------------------------
If you compile a project that has compiler warnings, javac's output indicates which Xlint option will suppress the warning. But when compiling the same code under maven-compiler-plugin, this vital information is suppressed so the user has a difficult time figuring out which option to use. Ideally the output should indicate which Xlint option corresponds to the warning.
Running mvn compile on the testcase results in:
[INFO] — maven-compiler-plugin:3.8.0:compile (default-compile) @ testcase —
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to C:\Users\Gili\Documents\3rdparty\testcase\target\classes
[WARNING] /C:/Users/Gili/Documents/3rdparty/testcase/src/main/java/module-info.java:[2,32] module not found: someOtherModule
Then running the following compilation:
javac -d C:\Users\Gili\Documents\3rdparty\testcase\target\classes -classpath C:\Users\Gili\Documents\3rdparty\testcase\target\classes; -sourcepath C:\Users\Gili\Documents\3rdparty\testcase\src\main\java;C:\Users\Gili\Documents\3rdparty\testcase\target\generated-sources\annotations; -s C:\Users\Gili\Documents\3rdparty\testcase\target\generated-sources\annotations -g -target 11 -source 11 -encoding UTF-8 com\company\SomeClass.java module-info.java
The following output is seen.
module-info.java:2: warning: [module] module not found: someOtherModule
exports com.company to someOtherModule;
^
1 warning
Notice that the javac output includes "[module]" at the beginning of the warning message. This indicates that "-Xlint:-module" will suppress this warning. I was expecting maven-plugin-compiler to show this information in its output.
As per maven-compiler-plugin team:
They use the result from compilation with this class https://docs.oracle.com/en/java/javase/17/docs/api/java.compiler/javax/tools/Diagnostic.html. In case of error/warning, they use the method diagnostic.getMessage(Locale.getDefault()) (
In this case the method returns module not found: someOtherModule but at the same time diagnostic.toString() is returning:
/Volumes/workspace/dev/sources/plexus/plexus-compiler/plexus-compiler-its/target/it/missing-warnings/src/main/java/module-info.java:2: warning: [module] module not found: someOtherModule
exports com.company to someOtherModule;
So suspecting this behavior as a JDK bug.
A reproducer code (Testcase.java) is also attached.
- relates to
-
JDK-6957438 improve code for generating warning messages containing option names
-
- Closed
-
- links to