2016-04-22 151 views
3

如果我想查看编译器输出,通常我为maven-compiler-plugin启用verbose选项。当fork选项用于maven-compiler-plugin时没有详细的输出

然而,当它与fork选项一起使用时,这将不起作用。 编译在另一个进程中运行,似乎maven不会将输出重定向到控制台。

我的代码示例如下所示

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>3.5.1</version> 
      <configuration> 
       <fork>true</fork> 
       <verbose>true</verbose> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

有谁知道我怎么能看到什么是在编译过程中发生了什么?

在这link我看到,一起使用这两个选项(fork和verbose)是鼓励。

但是,正如我已经提到的,在实践中,两个选项在使用 的时候不能很好地工作。

+0

可以确认这一点。奇怪的是,我找不到这方面的错误报告。最接近的似乎是https://issues.apache.org/jira/browse/MCOMPILER-81,但它是自动关闭= /。 – Tunaki

+0

@Tunaki我在其他开发者的同意下每年进行一次自动关闭以清理JIRA。至少三年未被触及的门票不会再被触及,无论他们是否重要。 –

+0

@ Michael-O我正在写一个答案,它看起来像一个丛编译器内部的错误。 – Tunaki

回答

4

UPDATE(25/06/2016):在plexus-compilerThis issue是固定的,在这个问题给定的代码将作为2.8版本。


通过源代码读取后,这是在2.7 plexus-compiler的一个错误,这是内部使用maven-compiler-plugin 3.5.1编译Java源库。

因此,它是这样的码:该maven-compiler-plugin填充称为CompilerConfiguration一个对象,并根据在POM中的给定的配置元件设置其forkverbose。所述verbose元件is correctly read and added to the compiler arguments

if (config.isVerbose()) 
{ 
    args.add("-verbose"); 
} 

然后,有一个开关depending on whether we're forking or not


如果我们没有,我们最终归结为代码调用javac,其输出is stored in the compilation result

ok = (Integer) compile.invoke(null, new Object[]{ args, new PrintWriter(out) }); 

messages = parseModernStream(ok.intValue(), new BufferedReader(new StringReader(out.toString()))); 

终于returned with

return new CompilerResult(success, messages); 

到目前为止,maven-compiler-plugin将环绕这些消息并将其输出到控制台。由于verbose参数已设置,我们将收到所有消息。


如果我们,然后一个可执行文件(默认为在路径中javac)检索和the compiler arguments are correctly set

for (String key : config.getCustomCompilerArgumentsAsMap().keySet()) 
{ 
    if (StringUtils.isNotEmpty(key) && key.startsWith("-J")) 
    { 
     cli.addArguments(new String[]{ key }); 
    } 
} 

我们可以通过调试模式下运行的Maven证实了这一点与-X,我们将看到消息:

[DEBUG] Excutable: 
[DEBUG] "C:\Program Files\Java\jdk1.8.0_74\bin\javac.exe" 
[DEBUG] Command line options: 
[DEBUG] -d ... -classpath ... -sourcepath ... -s ... -g -target 1.8 -source 1.8 -verbose 

最后注意-verbose

然后,这是错误。标准输出将被存储内的out可变

CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer(); 
正确用作编译方法的参数

but completely ignored afterwards

returnCode = CommandLineUtils.executeCommandLine(cli, out, err); 

messages = parseModernStream(returnCode, new BufferedReader(new StringReader(err.getOutput()))); 

通知如何消息,这将稍后形成插件输出的内容,仅填充错误而不填充标准输出。所以简单地说:标准输出在详细模式下被正确设置,但是它被忽略并且不被转换成正确的编译结果。


我没有看到解决方法(除了不分叉)。我在他们的GitHub中创建了issue 20来跟踪这个。

+0

你可能想用Plexus编译器报告。 PR是受欢迎的,我渴望合并。 –

+0

@ Michael-O是的,现在写一个问题:) – Tunaki

+0

@ Michael-O我创建了它。当我得到时间的时候会尝试修补一个补丁:)! – Tunaki

相关问题