使用Lambdas时,Maven插件构建失败

Sto*_*wke 16 java lambda maven-plugin maven java-8

我写了一个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]
Run Code Online (Sandbox Code Playgroud)

这是我的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>
Run Code Online (Sandbox Code Playgroud)

当我尝试使用lambda来定义一个FileFilter而不是传统的匿名内部类时,问题出现在这种情况下.

这有效:

List<File> controllerFiles = Arrays.asList(packageDirFile.listFiles(new FileFilter()
{
    @Override
    public boolean accept(File file)
    {
        return file.isFile() && file.getName().endsWith(".java");
    }
}));
Run Code Online (Sandbox Code Playgroud)

虽然这会产生上述错误:

List<File>
        controllerFiles =
        Arrays.asList(packageDirFile.listFiles(file -> file.isFile() &&
                file.getName().endsWith(".java")));
Run Code Online (Sandbox Code Playgroud)

显然,鉴于我有一个解决方法,这并不重要,但lambda比匿名内部类IMO更清晰,并且考虑到我在Java 8中工作,我更喜欢使用它.任何人都有任何提示,特别是考虑到我已经将skipErrorNoDescriptorsFound设置为true?

use*_*849 15

关于MPLUGIN-273的说明如果构建maven-plugin-plugin版本使用3.3版本,则lambda会起作用.显示的错误消息引用maven-plugin-plugin版本3.2.确保您使用的是正确版本的插件,看看是否能解决问题.


Sto*_*wke 7

我才意识到我回答了自己的问题.在我的第二个评论有一个Maven的JIRA问题,其中有人评论说,加大了链接maven-plugin-plugin的版本3.33.2修复问题,并尝试之后,我发现一样.所以这:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-plugin-plugin</artifactId>
    <version>3.2</version>
    ...    
</plugin>
Run Code Online (Sandbox Code Playgroud)

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-plugin-plugin</artifactId>
    <version>3.3</version>
    ...    
</plugin>
Run Code Online (Sandbox Code Playgroud)

问题就消失了.