当使用Eclipse和Maven构建一个包含一些简单lambda的不一致机器人的项目时,就会发生这种情况。
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.330 s
[INFO] Finished at: 2020-10-04T15:14:13+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project XXX: Compilation failure: Compilation failure:
[ERROR] /C:/XXX/listener/TextMessageListener.java:[24,54] lambda expressions are not supported in -source 7
[ERROR] (use -source 8 or higher to enable lambda expressions)
[ERROR] /C:/XXX/Main.java:[27,30] lambda expressions are not supported in -source 7
[ERROR] (use -source 8 or higher to enable lambda expressions)
[ERROR] /C:/XXX/Main.java:[33,38] method references are not supported in -source 7
[ERROR] (use -source 8 or higher to enable method references)
[ERROR] -> [Help 1]
[ERROR]
错误消息中给定位置的代码是例如
client.getEventDispatcher().on(MessageCreateEvent.class)
.map(MessageCreateEvent::getMessage)
.filter(message -> message.getAuthor().map(user -> !user.isBot()).orElse(false))
.flatMap(Message::getChannel)
.flatMap(channel -> onIncomingMessage(channel))
.subscribe();
我尝试在Eclipse Run菜单中执行Run as... -> Maven install
。
虽然使用了lambda,但它们绝对是正确的,所以这个错误不是来自代码中的错误。我该如何解决这个问题呢?
发布于 2020-10-04 21:27:10
好吧,问题出在我的项目的maven配置上。这些代码必须进行调整:
...
<version>0.0.1-SNAPSHOT</version>
<name>bot</name>
<url>mywebsite.site</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source> <---- to 1.8
<maven.compiler.target>1.7</maven.compiler.target> <---- to 1.8
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
...
调整pom.xml可以修复此错误。我想我应该在这里发布这个修复,因为我在网上找不到任何对这个特定错误有用的东西,所以我想我不妨把我辛辛苦苦付出的知识添加到互联网上(我花了大约2个小时,直到我偶然发现这个错误,但我也没有太多经验)。
https://stackoverflow.com/questions/64195190
复制相似问题