使用 Lambda 时,Maven 插件构建失败
2022-09-03 06:12:41
我写了一个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:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.my.group.id</groupId>
<artifactId>my-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1.0-SNAPSHOT</version>
<name>My Maven Mojo</name>
<url>http://maven.apache.org</url>
<properties>
<org.springframework.version>4.0.1.RELEASE</org.springframework.version>
<joda-time.version>2.3</joda-time.version>
</properties>
<dependencies>
<!-- several dependencies -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!-- The following manual call to the maven-plugin plugin is necessary to get around a bug in maven 3.1.1.
If the build server gets updated to 3.2.2+ we can remove this -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.2</version>
<configuration>
<!-- see http://jira.codehaus.org/browse/MNG-5346 -->
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
<executions>
<execution>
<id>mojo-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>inin-release</id>
<name>ININ Release Repository</name>
<url>http://nexus.infrastructure.inintca.com/nexus/content/repositories/inin-release</url>
</repository>
<snapshotRepository>
<id>inin-snapshot</id>
<name>ININ Snapshot Repository</name>
<url>http://nexus.infrastructure.inintca.com/nexus/content/repositories/inin-snapshot</url>
</snapshotRepository>
</distributionManagement>
</project>
在这种情况下,当我尝试使用 lambda 而不是传统的匿名内部类来定义时,问题就出现了。FileFilter
这有效:
List<File> controllerFiles = Arrays.asList(packageDirFile.listFiles(new FileFilter()
{
@Override
public boolean accept(File file)
{
return file.isFile() && file.getName().endsWith(".java");
}
}));
虽然这会产生上述错误:
List<File>
controllerFiles =
Arrays.asList(packageDirFile.listFiles(file -> file.isFile() &&
file.getName().endsWith(".java")));
显然,鉴于我有一个解决方法,这并不关键,但lambda比匿名内部类IMO干净得多,并且鉴于我在Java 8中工作,我更喜欢使用它。任何人都有任何提示,特别是考虑到我已经将skipErrorNoDescriptorsFound设置为true?