Java – Maven plugin build failed when using Lambdas

I wrote a maven plugin / mojo to generate some code The plug-in runs well and has built-in Java JDK 1.8

I see some strange behaviors. However, if I use the syntax before 1.8, it will be built, installed, etc., but once I use Java 8 lambda expression, I will receive 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]

This is my 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>

In this case, this problem occurs when I try to use lambda to define filefilter instead of the traditional anonymous inner class

Do it in this way.

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

Although this will cause the above error:

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

Obviously, since I have a solution, it doesn't matter, but lambda is cleaner than anonymous inner class IMO, and I work in Java 8. I prefer to use it Anyone has any hint, especially because I have set skiperrnodescriptorsfold to true?

Solution

The comments on mplugin-273 indicate that if the build uses Maven plugin plugin version 3.3, you can use Lambdas The displayed error message refers to Maven plugin plugin version 3.2 Make sure you are using the correct plug - in version to see if this problem is resolved

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>