加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – Maven Plugin Build使用Lambdas时失败

发布时间:2020-12-14 16:37:52 所属栏目:Java 来源:网络整理
导读:我写了一个maven插件/ mojo来生成一些代码.该插件运行良好,并且内置 Java Java JDK 1.8. 我看到一些奇怪的行为,尽管如此,如果我使用1.8之前的语法,它会构建,安装等等,但是一旦我使用Java 8 Lambda表达式,我在执行mvn clean install时会收到以下错误: [ERROR
我写了一个maven插件/ mojo来生成一些代码.该插件运行良好,并且内置 Java 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?

解决方法

MPLUGIN-273上的注释表示,如果构建使用maven-plugin-plugin 3.3版,则可以使用lambdas.显示的错误消息引用了maven-plugin-plugin 3.2版.确保您正在使用正确的插件版本,看看是否解决了这个问题.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读