Skip to content

System.out.println() in GenerateJdkToolchainsXmlMojo bypasses Maven logging infrastructure #172

Description

@elharo

Summary

GenerateJdkToolchainsXmlMojo uses System.out.println(writer) to output the generated toolchains XML, bypassing Maven's logging infrastructure. This output will not respect Maven's -q (quiet) or -X (debug) flags.

Location

GenerateJdkToolchainsXmlMojo.java:72

https://github.com/apache/maven-toolchains-plugin/blob/master/src/main/java/org/apache/maven/plugins/toolchain/jdk/GenerateJdkToolchainsXmlMojo.java#L72

Code

} else {
    StringWriter writer = new StringWriter();
    new MavenToolchainsXpp3Writer().write(writer, toolchains);
    System.out.println(writer);
}

Problem

Using System.out.println() instead of getLog().info():

  1. Bypasses Maven's logging system entirely
  2. Output appears on stdout even when -q (quiet mode) is used
  3. Output is not captured in Maven's log file
  4. The writer object is passed to println() instead of writer.toString(), which relies on StringWriter.toString() being called implicitly via println(Object), but this is fragile and depends on StringWriter.toString() being properly overridden (it is, but it's an indirect and non-obvious coding pattern)

Impact

Users running mvn -q generate-jdk-toolchains-xml will still see the XML output on stdout. The XML should either be written to a file (the -Dtoolchain.file path) or logged via the proper Maven logging API.

Suggested Fix

Use the Maven logger:

} else {
    StringWriter writer = new StringWriter();
    new MavenToolchainsXpp3Writer().write(writer, toolchains);
    getLog().info(writer.toString());
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions