While developing a maven plugin the build prints error:
[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]
even though that the file Iface.java
is compilable.
Iface.java
:
package org.example; public interface Iface { default String getString() { return "string"; } }
from 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>
What causes the problem? How it can be fixed?
The problem is that maven-plugin-plugin
generating plugin descriptor had difficulties to parse Java 8 interfaces with default methods.
It can be fixed by explicitly stating newer plugin version in 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>
Or just by avoiding default methods by moving their bodies to implementing classes.
Related bug: MPLUGIN-272
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With