使用Lambdas时,Maven插件构建失败
我写了一个maven插件/ mojo来生成一些代码。 该插件运行良好,并使用Java JDK 1.8构建。
我看到了一些奇怪的行为:它构建,安装等等,如果我使用1.8之前的语法,但是只要我使用Java 8 Lambda表达式,我在执行mvn clean install
时会收到以下错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor (default-descriptor) on project my-maven-plugin: Execution default-descriptor of goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor failed: 13557 -> [Help 1]
这是我的pom:
4.0.0 com.my.group.id my-maven-plugin maven-plugin 1.0-SNAPSHOT My Maven Mojo http://maven.apache.org 4.0.1.RELEASE 2.3 org.apache.maven.plugins maven-compiler-plugin 3.2 1.8 1.8 org.apache.maven.plugins maven-plugin-plugin 3.2 true mojo-descriptor descriptor inin-release ININ Release Repository http://nexus.infrastructure.inintca.com/nexus/content/repositories/inin-release inin-snapshot ININ Snapshot Repository http://nexus.infrastructure.inintca.com/nexus/content/repositories/inin-snapshot
当我尝试使用lambda来定义FileFilter
而不是传统的匿名内部类时,问题出现在这种情况下。
这有效:
List controllerFiles = Arrays.asList(packageDirFile.listFiles(new FileFilter() { @Override public boolean accept(File file) { return file.isFile() && file.getName().endsWith(".java"); } }));
虽然这会产生上述错误:
List controllerFiles = Arrays.asList(packageDirFile.listFiles(file -> file.isFile() && file.getName().endsWith(".java")));
显然,鉴于我有一个解决方法,这并不重要,但lambda比匿名内部类IMO更清晰,并且考虑到我在Java 8中工作,我更喜欢使用它。 任何人都有任何提示,特别是考虑到我已经将skipErrorNoDescriptorsFound设置为true?
关于MPLUGIN-273的说明如果构建使用maven-plugin-plugin
版本3.3,则lambdas可以工作。 显示的错误消息引用了maven-plugin-plugin
版本3.2 。 确保您使用的是正确版本的插件,看看是否能解决问题。
我才意识到我回答了自己的问题。 在我的第二个评论中,有一个Maven Jira问题的链接,其中有人评论说,将maven-plugin-plugin
版本从3.2
升级到3.3
修复了这个问题,在尝试之后我发现了同样的问题。 所以这:
org.apache.maven.plugins maven-plugin-plugin 3.2 ...
变
org.apache.maven.plugins maven-plugin-plugin 3.3 ...
问题就消失了。