英文:
Compilation failure: lambda expressions are not supported in -source 7
问题
以下是翻译好的内容:
使用Eclipse和Maven构建包含一些简单lambda表达式的discord机器人项目时,出现了以下问题。
[INFO] 构建失败
[INFO] ------------------------------------------------------------------------
[INFO] 总时间:5.330秒
[INFO] 完成于:2020-10-04T15:14:13+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] 无法执行目标org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile(default-compile),项目XXX:编译失败:编译失败:
[ERROR] /C:/XXX/listener/TextMessageListener.java:[24,54] 不支持lambda表达式在-source 7中
[ERROR] (请使用-source 8或更高版本以启用lambda表达式)
[ERROR] /C:/XXX/Main.java:[27,30] 不支持lambda表达式在-source 7中
[ERROR] (请使用-source 8或更高版本以启用lambda表达式)
[ERROR] /C:/XXX/Main.java:[33,38] 不支持方法引用在-source 7中
[ERROR] (请使用-source 8或更高版本以启用方法引用)
[ERROR] -> [帮助 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 as... -> Maven install”。
虽然代码中使用了lambda表达式,但它们肯定是正确的,所以这个错误不是由代码中的错误引起的。我该如何解决这个问题?
英文:
when using Eclipse and Maven to build a project that contains some simple lambda's for a discord bot, this happenes.
[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]
The code at the given places in the error message are e.g.
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();
I try to execute Run as... -> Maven install
in the Eclipse Run menu.
There are lambdas used, but they are definitely correct, so this error does not come from an error in the code. How can I fix this?
答案1
得分: 6
好的,以下是翻译好的部分:
问题出在我项目中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> <---- 改为 1.8
<maven.compiler.target>1.7</maven.compiler.target> <---- 改为 1.8
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
...
调整pom.xml可以修复这个错误。我认为我应该在这里发布这个修复方法,因为在网上没有找到与这个特定错误相关的任何有用信息,所以我想我不妨将我辛苦学到的知识添加到互联网上(我花了大约2个小时才偶然发现这个问题,但我经验不太丰富)。
英文:
Well, the problem lies in my configuration of maven for my project. These lines had to be adapted:
...
<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>
...
Adapting the pom.xml fixes this error. I'd thought I'd post this fix here, because I didn't find ANYTHING useful to this specific error online, so I thought I might as well add my hard payed knowledge to the internet (I spent some 2 hours until I discovered this by accident, but I'm not very experienced, too).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论