maven-compiler-plugin fails to compile a file that Eclipse has no problem with [duplicate]

天大地大妈咪最大 提交于 2019-12-11 07:57:54

问题


Eclipse compiles the following code without any problem, whereas when mvn tries to compile this code, a compilation failure results:

try {
    // Distribution.rep().get(id) returns a java.util.Optional
    Distribution updated = Distribution.rep().transact(() -> {
        Distribution distro = Distribution.rep().get(id).orElseThrow(() -> {
            throw new NotFoundException("Couldn't find Distribution with ID '%s'.", id);
        });
        // Other stuff...
    });
    rs.setData(updated);
} catch (ExecutionException e) {
    // Handle the error
} catch (Exception e) {
    // Handle the exception
}

The error thrown by maven-compiler-plugin:3.1 is:

unreported exception java.lang.Throwable; must be caught or declared to be thrown

NotFoundException extends RuntimeException. The transact method wraps all runtime (?) exceptions in an ExecutionException before throwing them. Either way, this NotFoundException (when thrown) should get caught by the catch clause for ExecutionException, so what's the problem?

From what I can understand the maven-compiler-plugin seems to think that the NotFoundException is a Throwable. NotFoundException is defined in my code (project), so maven-compiler-pluginshould know about it...

Source and target for the compiler plugin are defined as 1.8. Have Java version 1.8.0_181. Tried with maven-compiler-plugin version 3.8.0, got the same result.

来源:https://stackoverflow.com/questions/54140830/maven-compiler-plugin-fails-to-compile-a-file-that-eclipse-has-no-problem-with

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!