maven-plugin-plugin:描述符目标在文件和文件中失败

时间:2016-07-23 23:15:50

标签: maven java-8 maven-plugin default-method

在开发maven插件时,构建会输出错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-plugin-plugin:3.3:descriptor (default-descriptor) on project default-method-demo: Execution default-descriptor of goal org.apache.maven.plugins:maven-plugin-plugin:3.3:descriptor failed: syntax error @[8,1] in file:/full/path/to/project/default-method/src/main/java/org/example/Iface.java -> [Help 1]

即使文件Iface.java是可编辑的。

Iface.java

package org.example;

public interface Iface {
    default String getString() {
        return "string";
    }
}

来自pom.xml

<packaging>maven-plugin</packaging>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-plugin-api</artifactId>
        <version>3.0.5</version>
    </dependency>
    <dependency>
        <groupId>org.apache.maven.plugin-tools</groupId>
        <artifactId>maven-plugin-annotations</artifactId>
        <version>3.4</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

导致问题的原因是什么?如何解决?

1 个答案:

答案 0 :(得分:39)

问题是maven-plugin-plugin生成插件描述符很难用默认方法解析Java 8接口。

可以通过在pom.xml中明确说明较新的插件版本来修复它:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-plugin-plugin</artifactId>
            <version>3.4</version>
        </plugin>
        <!-- other plugins -->
    </plugins>
</build>

或者只是通过将他们的身体移动到实现类来避免默认方法。

相关错误:MPLUGIN-272