【问题标题】:How do I get Maven to emit compile errors like javac does?如何让 Maven 像 javac 一样发出编译错误?
【发布时间】:2014-11-29 01:03:56
【问题描述】:

在 Java 中,如果我的源代码中有一个不提供正确参数类型的方法调用,或者如果我尝试为一种类型的变量分配另一种不兼容类型的值,那么这将引发编译错误,因为它应该。但是,当使用 Maven (mvn) 时,编译错误将类似于(取自真实代码)

error: method put in interface Map<K,V> cannot be applied to given types;

句号。然而,当使用 javac (javac) 时,编译错误将类似于

error: method put in interface Map<K,V> cannot be applied to given types;

        elements.put(coords, val);}
                ^
  required: Integer[],T
  found: int[],T
  reason: actual argument int[] cannot be converted to Integer[] by method invocation conversion
  where T,K,V are type-variables:
    T extends Object declared in class Grid
    K extends Object declared in interface Map
    V extends Object declared in interface Map

我认为这更有帮助。

如何让 Maven 像 javac 一样发出编译错误?特别是,我如何让它提供更多的上下文信息?

顺便说一下,-e 和 -X 切换到 mvn 并不能解决这个问题。

【问题讨论】:

    标签: java maven


    【解决方案1】:

    您可能正在使用 2.5.1 或更低版本的 Maven 编译器插件。

    如果您使用 3.0 版,您实际上会收到更详细的错误消息:

    [ERROR] required: java.lang.String,java.lang.String
    [ERROR] found: int,int
    [ERROR] reason: actual argument int cannot be converted to java.lang.String by method    invocation conversion
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-02
    • 2014-01-07
    • 2012-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-03
    • 1970-01-01
    相关资源
    最近更新 更多