Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven 3.7.0 compile java 8 project encount incompatibility API

Tags:

java

maven

When I am compile Java project using this command:

mvn install

Throw this error:

    [INFO] Changes detected - recompiling the module!
[INFO] Compiling 1158 source files to /var/lib/jenkins/workspace/xycq-web-ci/cqnews-online/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.172 s
[INFO] Finished at: 2018-06-16T12:47:50+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project cqnews-online: Execution default-compile of goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile failed: An API incompatibility was encountered while executing org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile: java.lang.NoSuchMethodError: org.codehaus.plexus.compiler.CompilerError: method <init>(Ljava/lang/String;ZIIIILjava/lang/String;)V not found
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>org.apache.maven.plugins:maven-compiler-plugin:3.7.0
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/opt/haishu/local/repo/m2/repository/org/apache/maven/plugins/maven-compiler-plugin/3.7.0/maven-compiler-plugin-3.7.0.jar
[ERROR] urls[1] = file:/opt/haishu/local/repo/m2/repository/org/codehaus/plexus/plexus-compiler-javac/1.8.1/plexus-compiler-javac-1.8.1.jar

This is my compile project pom.xml configuration:

 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>

This is my operation system and java enviroment information:

[root@firewalld cqnews-online]# mvn -v
Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-25T03:49:05+08:00)
Maven home: /opt/haishu/local/apache-maven-3.5.3
Java version: 1.8.0_151, vendor: Oracle Corporation
Java home: /opt/haishu/local/jdk1.8.0_151/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-693.el7.x86_64", arch: "amd64", family: "unix"
like image 427
Dolphin Avatar asked Oct 29 '22 10:10

Dolphin


1 Answers

Two steps to fix this problem:

  1. change to eclipse compiler
  2. upgrade the version to 2.x+

This is the configuration:

           <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                    <compilerId>eclipse</compilerId>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.codehaus.plexus</groupId>
                        <artifactId>plexus-compiler-eclipse</artifactId>
                        <version>2.8.4</version>
                    </dependency>
                    <dependency>
                        <groupId>org.codehaus.plexus</groupId>
                        <artifactId>plexus-compiler-javac</artifactId>
                        <version>2.8.4</version>
                    </dependency>
                </dependencies>
            </plugin>
like image 50
Dolphin Avatar answered Nov 15 '22 05:11

Dolphin