使用Lambdas时,Maven插件构建失败
我写了一个maven插件/ mojo来生成一些代码。该插件运行良好,并使用Java JDK 1.8构建。
I wrote a maven plugin/mojo to generate some code. The plugin works well, and is built in Java JDK 1.8.
我看到了一些奇怪的行为:它构建,安装等等,如果我使用pre -1.8语法,但是一旦我使用Java 8 Lambda表达式,执行 mvn clean install
时会出现以下错误:
I am seeing an odd bit of behavior though: It builds, installs, etc just fine if I use pre-1.8 syntax, but as soon as I use a Java 8 Lambda expression, I get the following error when executing 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
而不是传统的匿名内部类。
The issue appears in this case when I attempt to use a lambda to define a FileFilter
rather than the traditional anonymous inner class.
这有效:
List<File> controllerFiles = Arrays.asList(packageDirFile.listFiles(new FileFilter()
{
@Override
public boolean accept(File file)
{
return file.isFile() && file.getName().endsWith(".java");
}
}));
虽然这会产生上述错误:
While this produces the aforementioned error:
List<File>
controllerFiles =
Arrays.asList(packageDirFile.listFiles(file -> file.isFile() &&
file.getName().endsWith(".java")));
显然,鉴于我有一个解决方法,这并不重要,但lambda比匿名内部类IMO,鉴于我在Java 8中工作,我更喜欢使用它。任何人都有任何提示,特别是考虑到我已经将skipErrorNoDescriptorsFound设置为true?
Obviously given that I have a workaround this isn't critical, but the lambda is much cleaner than the anonymous inner class IMO and given that I'm working in Java 8 I'd much prefer to use it. Anybody have any tips, particularly given that I've already set skipErrorNoDescriptorsFound to true?
MPLUGIN-273 说如果构建使用 maven-plugin-plugin
,lambda就可以工作版本 3.3 。显示的错误消息引用了 maven-plugin-plugin
版本 3.2 。确保您使用的是正确版本的插件,看看是否能解决问题。
The note on MPLUGIN-273 says lambdas work if the build is using maven-plugin-plugin
version 3.3. The error message shown references maven-plugin-plugin
version 3.2 . Make sure you're using the correct version of the plugin and see if that fixes the issue.