Maven build Compilation error : Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Maven

前端 未结 19 1536
说谎
说谎 2020-12-01 01:17

I have a maven project forked and cloned from a git repo onto my eclipse. It is build on Java 8. The first thing i do is perform a

mvn clean install


        
相关标签:
19条回答
  • 2020-12-01 01:51

    make sure java home path is correct. for my case, java home path is wrong in pom file.

      <properties>
            <java.home>/usr/java/jdk1.8.0_45/bin/javac</java.home>
      </properties>
    
    
    
    
                  <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-compiler-plugin</artifactId>
                            <version>3.5.1</version>
                    <configuration>
                          <verbose>true</verbose>
                          <fork>true</fork>
                          <executable>${java.home}</executable>
                       <compilerVersion>1.8</compilerVersion>
                       <source>1.8</source>
                       <target>1.8</target>
                     </configuration>
                 </plugin>
    
    0 讨论(0)
  • 2020-12-01 01:51

    I had the same problem, the solution was set JAVA_HOME in environment variables.

    0 讨论(0)
  • 2020-12-01 01:54

    If your local jdk version is 11 or 9, 10, and your project's java source/target version is 1.8, and you are using org.projectlombok:lombok package, then you can try to update its version to 1.16.22 or 1.18.12, like this:

            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.16.22</version>
            </dependency>
    

    It just solved my issue.

    0 讨论(0)
  • 2020-12-01 01:57

    You should add the code into pom.xml like:

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    
    0 讨论(0)
  • 2020-12-01 01:59

    I had the same problem and I Changed this

    <configuration>
        <source>1.7</source>
        <target>1.7</target>
     </configuration>
    

    here 1.7 is my JDK version.it was solved.

    0 讨论(0)
  • 2020-12-01 02:01

    The error occurred because the code is not for the default compiler used there. Paste this code in effective POM before the root element ends, after declaring dependencies, to change the compiler used. Adjust version as you need.

    <dependencies>
    ...
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    
    0 讨论(0)
提交回复
热议问题