mojo-executor を使用して別の Mojo を実行する Maven Mojo を作成しました。これが実行されると、その Mojo 実行の出力はデフォルトの出力になります。したがって、実行されると、次のように出力されます。
[INFO] Compiling 1 source file to /Users/sergio/hello-world/target/classes
[INFO]
[INFO] --- utqg-maven-plugin:1.1.0-SNAPSHOT:errorprone (default) @ my-app ---
/Users/sergio/hello-world/src/test/java/com/mycompany/App2Test.java:30: warning: [UTQG:HelperMethodCannotBePublic] Helper Methods of test classes cannot be public.
public String getName() {
^
(see https://www.mycompany.com/utqg/HelperMethodCannotBePublic)
/Users/sergio/hello-world/src/test/java/com/mycompany/service/MyServiceTest.java:14: warning: [UTQG:HelperMethodCannotBePublic] Helper Methods of test classes cannot be public.
public void myHelperMethod(){
^
(see https://www.mycompany.com/utqg/HelperMethodCannotBePublic)
/Users/sergio/hello-world/src/test/java/com/mycompany/service/MyServiceTest.java:170: warning: [UTQG:E:UseDeprecatedStatementsNotAllowed] Usage of Deprecated Classes, Methods or Variables Not Allowed
final URL url = new File(".").toURL();
^
(see https://www.mycompany.com/utqg/HelperMethodCannotBePublic)
Note: /Users/sergio/hello-world/src/test/java/com/mycompany/service/MyServiceTest.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
3 warnings
OK、Errorprone を使用していくつかのバグチェッカーを作成したため、これらの警告はすべて予想されます。しかし問題は、この出力を標準出力から削除して、ファイルに入れなければならないことです。でもその部分だけ。
私がこれまでに試したことは、実行時に出力をファイルにリダイレクトすることでした:
PrintStream originalStream = System.out;
try {
PrintStream ps = new PrintStream(new FileOutputStream(ERRORPRONE_FILE, false));
System.setOut(ps);
} catch (FileNotFoundException e){
LOGGER.error("ErrorProneRunMojo", e);
throw new MojoExecutionException(e.getMessage());
}
// do my logic of calling the plugin here
System.out.flush();
System.setOut(originalStream);
前提: - 標準出力からすべてを削除してファイル内に配置するため、使用できませんmvn --logFile
。-l
また、ユーザーが --logFile またはそのようなものを配置しても、ソリューションは信頼できないはずです。