maven-compiler-plugin 无法编译 Eclipse 没有问题的文件[重复]

2024-05-01

Eclipse 编译以下代码没有任何问题,而当mvn尝试编译此代码,结果编译失败:

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
}

抛出的错误maven-compiler-plugin:3.1 is:

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

NotFoundException extends RuntimeException. The transact方法将所有运行时(?)异常包装在一个ExecutionException在扔掉它们之前。不管怎样,这NotFoundException(抛出时)应该被catch条款为ExecutionException, 所以有什么问题?

据我所知maven-compiler-plugin似乎认为NotFoundException is a Throwable. NotFoundException在我的代码(项目)中定义,所以maven-compiler-plugin应该知道这件事...

编译器插件的源和目标定义为1.8。有Java版本1.8.0_181。尝试过maven-compiler-plugin版本3.8.0,得到相同的结果。


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

maven-compiler-plugin 无法编译 Eclipse 没有问题的文件[重复] 的相关文章

随机推荐